diff options
| author | Stefan Monnier | 2000-09-19 16:24:30 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-09-19 16:24:30 +0000 |
| commit | c0aa75f75ef4288e7f5bf52cc519085c7c08204b (patch) | |
| tree | 0402f778371d3c3584705d3b5abb0009b5fc4582 | |
| parent | da1608d95936c0fbe15d3812fc3bb178a3cf67bb (diff) | |
| download | emacs-c0aa75f75ef4288e7f5bf52cc519085c7c08204b.tar.gz emacs-c0aa75f75ef4288e7f5bf52cc519085c7c08204b.zip | |
Docstring fixes.
(diff-header-face, diff-comment-face): New faces.
(diff-font-lock-keywords): Highlight a bit differently.
(diff-find-source-location): Don't return SPAN any more.
(diff-hunk-text): Don't bother erasing the temp buffer.
(diff-find-text): Drop argument LINE.
(diff-apply-hunk): Update calls to diff-find-text.
(diff-goto-source): Use pop-to-buffer again and don't raise an error.
| -rw-r--r-- | lisp/diff-mode.el | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index a147390fe59..3d280e7ccd5 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.14 2000/09/18 08:15:38 miles Exp $ | 7 | ;; Revision: $Id: diff-mode.el,v 1.15 2000/09/19 02:43:33 miles Exp $ |
| 8 | 8 | ||
| 9 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| 10 | 10 | ||
| @@ -163,67 +163,74 @@ when editing big diffs)." | |||
| 163 | ;;;; font-lock support | 163 | ;;;; font-lock support |
| 164 | ;;;; | 164 | ;;;; |
| 165 | 165 | ||
| 166 | (defface diff-header-face | ||
| 167 | '((t (:inherit highlight))) | ||
| 168 | "`diff-mode' face inherited by hunk, file and index header faces." | ||
| 169 | :group 'diff-mode) | ||
| 170 | (defvar diff-header-face 'diff-header-face) | ||
| 171 | |||
| 166 | (defface diff-file-header-face | 172 | (defface diff-file-header-face |
| 167 | '((((class color) (background light)) | 173 | '((t (:bold t))) ;; :height 1.3 |
| 168 | (:background "grey70" :bold t)) | 174 | "`diff-mode' face used to highlight file header lines." |
| 169 | (t (:bold t))) | ||
| 170 | "diff-mode face used to highlight file header lines." | ||
| 171 | :group 'diff-mode) | 175 | :group 'diff-mode) |
| 172 | (defvar diff-file-header-face 'diff-file-header-face) | 176 | (defvar diff-file-header-face 'diff-file-header-face) |
| 173 | 177 | ||
| 174 | (defface diff-index-face | 178 | (defface diff-index-face |
| 175 | '((((class color) (background light)) | 179 | '((t (:inherit diff-file-header-face))) |
| 176 | (:background "grey70" :bold t)) | 180 | "`diff-mode' face used to highlight index header lines." |
| 177 | (t (:bold t))) | ||
| 178 | "diff-mode face used to highlight index header lines." | ||
| 179 | :group 'diff-mode) | 181 | :group 'diff-mode) |
| 180 | (defvar diff-index-face 'diff-index-face) | 182 | (defvar diff-index-face 'diff-index-face) |
| 181 | 183 | ||
| 182 | (defface diff-hunk-header-face | 184 | (defface diff-hunk-header-face |
| 183 | '((((class color) (background light)) | 185 | '((t (:inherit diff-header-face))) |
| 184 | (:background "grey85")) | 186 | "`diff-mode' face used to highlight hunk header lines." |
| 185 | (t (:bold t))) | ||
| 186 | "diff-mode face used to highlight hunk header lines." | ||
| 187 | :group 'diff-mode) | 187 | :group 'diff-mode) |
| 188 | (defvar diff-hunk-header-face 'diff-hunk-header-face) | 188 | (defvar diff-hunk-header-face 'diff-hunk-header-face) |
| 189 | 189 | ||
| 190 | (defface diff-removed-face | 190 | (defface diff-removed-face |
| 191 | '((t ())) | 191 | '((t (:inherit diff-changed-face))) |
| 192 | "diff-mode face used to highlight removed lines." | 192 | "`diff-mode' face used to highlight removed lines." |
| 193 | :group 'diff-mode) | 193 | :group 'diff-mode) |
| 194 | (defvar diff-removed-face 'diff-removed-face) | 194 | (defvar diff-removed-face 'diff-removed-face) |
| 195 | 195 | ||
| 196 | (defface diff-added-face | 196 | (defface diff-added-face |
| 197 | '((t ())) | 197 | '((t (:inherit diff-changed-face))) |
| 198 | "diff-mode face used to highlight added lines." | 198 | "`diff-mode' face used to highlight added lines." |
| 199 | :group 'diff-mode) | 199 | :group 'diff-mode) |
| 200 | (defvar diff-added-face 'diff-added-face) | 200 | (defvar diff-added-face 'diff-added-face) |
| 201 | 201 | ||
| 202 | (defface diff-changed-face | 202 | (defface diff-changed-face |
| 203 | '((t ())) | 203 | '((t ())) |
| 204 | "diff-mode face used to highlight changed lines." | 204 | "`diff-mode' face used to highlight changed lines." |
| 205 | :group 'diff-mode) | 205 | :group 'diff-mode) |
| 206 | (defvar diff-changed-face 'diff-changed-face) | 206 | (defvar diff-changed-face 'diff-changed-face) |
| 207 | 207 | ||
| 208 | (defface diff-comment-face | ||
| 209 | '((t (:inherit font-lock-comment-face))) | ||
| 210 | "`diff-mode' face used to highlight context and other side-information." | ||
| 211 | :group 'diff-mode) | ||
| 212 | (defvar diff-comment-face 'diff-comment-face) | ||
| 213 | |||
| 208 | (defvar diff-font-lock-keywords | 214 | (defvar diff-font-lock-keywords |
| 209 | '(("^@@ \\(-[0-9,]+ \\+[0-9,]+\\) @@\\(.*\\)$" ;unified | 215 | '(("^\\(@@ -[0-9,]+ \\+[0-9,]+ @@\\)\\(.*\\)$" ;unified |
| 210 | (1 diff-hunk-header-face) | 216 | (1 diff-hunk-header-face) |
| 211 | (2 font-lock-comment-face)) | 217 | (2 diff-comment-face)) |
| 212 | ("^--- \\(.+\\) ----$" ;context | 218 | ("^--- .+ ----$" ;context |
| 213 | (1 diff-hunk-header-face)) | 219 | . diff-hunk-header-face) |
| 214 | ("\\(\\*\\{15\\}\\)\\(.*\\)\n" ;context | 220 | ("\\(\\*\\{15\\}\\)\\(.*\\)$" ;context |
| 215 | (1 diff-hunk-header-face) | 221 | (1 diff-hunk-header-face) |
| 216 | (2 font-lock-comment-face)) | 222 | (2 diff-comment-face)) |
| 217 | ("^\\*\\*\\* \\(.+\\) \\*\\*\\*" ;context | 223 | ("^\\*\\*\\* .+ \\*\\*\\*\\*" ;context |
| 218 | (1 diff-hunk-header-face)) | 224 | . diff-hunk-header-face) |
| 219 | ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\)" (2 diff-file-header-face)) | 225 | ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\).*[^*-]\n" |
| 226 | (0 diff-header-face) (2 diff-file-header-face prepend)) | ||
| 220 | ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) | 227 | ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) |
| 221 | ("^!.*\n" . diff-changed-face) ;context | 228 | ("^!.*\n" . diff-changed-face) ;context |
| 222 | ("^[+>].*\n" . diff-added-face) | 229 | ("^[+>].*\n" . diff-added-face) |
| 223 | ("^[-<].*\n" . diff-removed-face) | 230 | ("^[-<].*\n" . diff-removed-face) |
| 224 | ("^Index: \\(.+\\)$" (1 diff-index-face)) | 231 | ("^Index: \\(.+\\).*\n" (0 diff-header-face) (1 diff-index-face prepend)) |
| 225 | ("^#.*" . font-lock-string-face) | 232 | ("^#.*" . font-lock-string-face) |
| 226 | ("^[^-=+*!<>].*\n" . font-lock-comment-face))) | 233 | ("^[^-=+*!<>].*\n" . diff-comment-face))) |
| 227 | 234 | ||
| 228 | (defconst diff-font-lock-defaults | 235 | (defconst diff-font-lock-defaults |
| 229 | '(diff-font-lock-keywords t nil nil nil (font-lock-multiline . nil))) | 236 | '(diff-font-lock-keywords t nil nil nil (font-lock-multiline . nil))) |
| @@ -441,7 +448,7 @@ Non-nil OLD means that we want the old file." | |||
| 441 | file))))) | 448 | file))))) |
| 442 | 449 | ||
| 443 | (defun diff-find-source-location (&optional other-file) | 450 | (defun diff-find-source-location (&optional other-file) |
| 444 | "Find out (FILE LINE SPAN)." | 451 | "Find out (FILE LINE)." |
| 445 | (save-excursion | 452 | (save-excursion |
| 446 | (diff-beginning-of-hunk) | 453 | (diff-beginning-of-hunk) |
| 447 | (let* ((old (if (not other-file) diff-jump-to-old-file-flag | 454 | (let* ((old (if (not other-file) diff-jump-to-old-file-flag |
| @@ -454,22 +461,12 @@ Non-nil OLD means that we want the old file." | |||
| 454 | (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t) | 461 | (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t) |
| 455 | (error "Can't find the hunk separator")) | 462 | (error "Can't find the hunk separator")) |
| 456 | (match-string 1))))) | 463 | (match-string 1))))) |
| 457 | ;; Extract the actual line number. | 464 | (file (diff-find-file-name old))) |
| 458 | (lines (if (string-match "^\\([0-9]*\\),\\([0-9]*\\)" loc) | ||
| 459 | (cons (string-to-number (match-string 1 loc)) | ||
| 460 | (string-to-number (match-string 2 loc))) | ||
| 461 | (cons (string-to-number loc) nil))) | ||
| 462 | (file (diff-find-file-name old)) | ||
| 463 | (line (car lines)) | ||
| 464 | (span (if (or (null (cdr lines)) (< (cdr lines) 0)) 0 | ||
| 465 | ;; Bad hack. | ||
| 466 | (if (< (cdr lines) line) (cdr lines) | ||
| 467 | (- (cdr lines) line))))) | ||
| 468 | ;; Update the user preference if he so wished. | 465 | ;; Update the user preference if he so wished. |
| 469 | (when (> (prefix-numeric-value other-file) 8) | 466 | (when (> (prefix-numeric-value other-file) 8) |
| 470 | (setq diff-jump-to-old-file-flag old)) | 467 | (setq diff-jump-to-old-file-flag old)) |
| 471 | (if (null file) (error "Can't find the file") | 468 | (if (null file) (error "Can't find the file") |
| 472 | (list file line span))))) | 469 | (list file (string-to-number loc)))))) |
| 473 | 470 | ||
| 474 | (defun diff-mouse-goto-source (event) | 471 | (defun diff-mouse-goto-source (event) |
| 475 | "Run `diff-goto-source' for the diff at a mouse click." | 472 | "Run `diff-goto-source' for the diff at a mouse click." |
| @@ -882,12 +879,12 @@ Only works for unified diffs." | |||
| 882 | (equal (match-string 1) (match-string 2))))) | 879 | (equal (match-string 1) (match-string 2))))) |
| 883 | 880 | ||
| 884 | (defun diff-hunk-text (hunk destp &optional line-offset) | 881 | (defun diff-hunk-text (hunk destp &optional line-offset) |
| 885 | "Returns the literal source text from HUNK, if DESTP is nil, otherwise the | 882 | "Returns the literal source text from HUNK. |
| 886 | destination text. If LINE-OFFSET is non-nil, it should be a line-offset in | 883 | if DESTP is nil return the source, otherwise the destination text. |
| 884 | If LINE-OFFSET is non-nil, it should be a line-offset in | ||
| 887 | HUNK, and instead of a string, a cons cell is returned whose car is the | 885 | HUNK, and instead of a string, a cons cell is returned whose car is the |
| 888 | appropriate text, and whose cdr is the corresponding line-offset in that text." | 886 | appropriate text, and whose cdr is the corresponding line-offset in that text." |
| 889 | (with-temp-buffer | 887 | (with-temp-buffer |
| 890 | (erase-buffer) | ||
| 891 | (insert hunk) | 888 | (insert hunk) |
| 892 | (goto-char (point-min)) | 889 | (goto-char (point-min)) |
| 893 | (let ((src-pos nil) | 890 | (let ((src-pos nil) |
| @@ -962,10 +959,9 @@ appropriate text, and whose cdr is the corresponding line-offset in that text." | |||
| 962 | (cons text (count-lines (point-min) (point))) | 959 | (cons text (count-lines (point-min) (point))) |
| 963 | text)))))) | 960 | text)))))) |
| 964 | 961 | ||
| 965 | (defun diff-find-text (text line) | 962 | (defun diff-find-text (text) |
| 966 | "Return the buffer position of the nearest occurance of TEXT to line LINE. | 963 | "Return the buffer position of the nearest occurance of TEXT. |
| 967 | If TEXT isn't found, nil is returned." | 964 | If TEXT isn't found, nil is returned." |
| 968 | (goto-line line) | ||
| 969 | (let* ((orig (point)) | 965 | (let* ((orig (point)) |
| 970 | (forw (and (search-forward text nil t) | 966 | (forw (and (search-forward text nil t) |
| 971 | (match-beginning 0))) | 967 | (match-beginning 0))) |
| @@ -1023,11 +1019,14 @@ was non-nil." | |||
| 1023 | (old (diff-hunk-text hunk reverse hunk-line-offset)) | 1019 | (old (diff-hunk-text hunk reverse hunk-line-offset)) |
| 1024 | (new (diff-hunk-text hunk (not reverse) hunk-line-offset)) | 1020 | (new (diff-hunk-text hunk (not reverse) hunk-line-offset)) |
| 1025 | (pos | 1021 | (pos |
| 1026 | (with-current-buffer buf (diff-find-text (car old) patch-line))) | 1022 | (with-current-buffer buf |
| 1023 | (goto-line patch-line) | ||
| 1024 | (diff-find-text (car old)))) | ||
| 1027 | (reversed-pos | 1025 | (reversed-pos |
| 1028 | (and (null pos) | 1026 | (and (null pos) |
| 1029 | (with-current-buffer buf | 1027 | (with-current-buffer buf |
| 1030 | (diff-find-text (car new) patch-line))))) | 1028 | (goto-line patch-line) |
| 1029 | (diff-find-text (car new)))))) | ||
| 1031 | 1030 | ||
| 1032 | (when (and reversed-pos popup) | 1031 | (when (and reversed-pos popup) |
| 1033 | ;; A reversed patch was detected, perhaps apply it in reverse | 1032 | ;; A reversed patch was detected, perhaps apply it in reverse |
| @@ -1115,9 +1114,9 @@ If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[u | |||
| 1115 | (or (diff-apply-hunk nil other-file t 'select t) | 1114 | (or (diff-apply-hunk nil other-file t 'select t) |
| 1116 | ;; couldn't actually find the hunk, just obey the hunk line number | 1115 | ;; couldn't actually find the hunk, just obey the hunk line number |
| 1117 | (let ((loc (diff-find-source-location other-file))) | 1116 | (let ((loc (diff-find-source-location other-file))) |
| 1118 | (find-file-other-window (car loc)) | 1117 | (pop-to-buffer (find-file-noselect (car loc))) |
| 1119 | (goto-line (cadr loc)) | 1118 | (goto-line (cadr loc)) |
| 1120 | (error "Hunk text not found")))) | 1119 | (message "Hunk text not found")))) |
| 1121 | 1120 | ||
| 1122 | 1121 | ||
| 1123 | ;; provide the package | 1122 | ;; provide the package |