diff options
| author | Stefan Monnier | 2008-02-19 21:31:20 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-02-19 21:31:20 +0000 |
| commit | 5f082d1fe6ac28872c48095a77294a28b69deec2 (patch) | |
| tree | d4ac2b9b830a27d70999b2df69b99ebdeee4ff35 /lisp/diff-mode.el | |
| parent | 95dfb89d87037faadbe95226472d06af56432a2c (diff) | |
| download | emacs-5f082d1fe6ac28872c48095a77294a28b69deec2.tar.gz emacs-5f082d1fe6ac28872c48095a77294a28b69deec2.zip | |
(diff-file-junk-re): New const.
(diff-beginning-of-file-and-junk): Use it.
(diff-file-kill): Make sure we were really inside a file diff.
Diffstat (limited to 'lisp/diff-mode.el')
| -rw-r--r-- | lisp/diff-mode.el | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index e011ce17e1e..5a01793d06e 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -501,11 +501,19 @@ If the prefix ARG is given, restrict the view to the current file instead." | |||
| 501 | (diff-end-of-hunk) | 501 | (diff-end-of-hunk) |
| 502 | (kill-region start (point))))) | 502 | (kill-region start (point))))) |
| 503 | 503 | ||
| 504 | (defconst diff-file-junk-re "diff \\|index ") ; "index " is output by git-diff. | ||
| 505 | |||
| 504 | (defun diff-beginning-of-file-and-junk () | 506 | (defun diff-beginning-of-file-and-junk () |
| 505 | "Go to the beginning of file-related diff-info. | 507 | "Go to the beginning of file-related diff-info. |
| 506 | This is like `diff-beginning-of-file' except it tries to skip back over leading | 508 | This is like `diff-beginning-of-file' except it tries to skip back over leading |
| 507 | data such as \"Index: ...\" and such." | 509 | data such as \"Index: ...\" and such." |
| 508 | (let ((start (point)) | 510 | (let ((orig (point)) |
| 511 | ;; Skip forward over what might be "leading junk" so as to get | ||
| 512 | ;; closer to the actual diff. | ||
| 513 | (_ (progn (beginning-of-line) | ||
| 514 | (while (looking-at diff-file-junk-re) | ||
| 515 | (forward-line 1)))) | ||
| 516 | (start (point)) | ||
| 509 | (file (condition-case err (progn (diff-beginning-of-file) (point)) | 517 | (file (condition-case err (progn (diff-beginning-of-file) (point)) |
| 510 | (error err))) | 518 | (error err))) |
| 511 | ;; prevhunk is one of the limits. | 519 | ;; prevhunk is one of the limits. |
| @@ -521,20 +529,28 @@ data such as \"Index: ...\" and such." | |||
| 521 | (re-search-backward "^Index: " prevhunk t)))) | 529 | (re-search-backward "^Index: " prevhunk t)))) |
| 522 | (when index (setq file index)) | 530 | (when index (setq file index)) |
| 523 | (if (<= file start) | 531 | (if (<= file start) |
| 524 | (goto-char file) | 532 | (progn |
| 533 | (goto-char file) | ||
| 534 | ;; Now skip backward over the leading junk we may have before the | ||
| 535 | ;; diff itself. | ||
| 536 | (while (save-excursion | ||
| 537 | (and (zerop (forward-line -1)) | ||
| 538 | (looking-at diff-file-junk-re))) | ||
| 539 | (forward-line -1))) | ||
| 525 | ;; File starts *after* the starting point: we really weren't in | 540 | ;; File starts *after* the starting point: we really weren't in |
| 526 | ;; a file diff but elsewhere. | 541 | ;; a file diff but elsewhere. |
| 527 | (goto-char start) | 542 | (goto-char orig) |
| 528 | (signal (car err) (cdr err)))))) | 543 | (signal (car err) (cdr err)))))) |
| 529 | 544 | ||
| 530 | (defun diff-file-kill () | 545 | (defun diff-file-kill () |
| 531 | "Kill current file's hunks." | 546 | "Kill current file's hunks." |
| 532 | (interactive) | 547 | (interactive) |
| 533 | (diff-beginning-of-file-and-junk) | 548 | (let ((orig (point)) |
| 534 | (let* ((start (point)) | 549 | (start (progn (diff-beginning-of-file-and-junk) (point))) |
| 535 | (inhibit-read-only t)) | 550 | (inhibit-read-only t)) |
| 536 | (diff-end-of-file) | 551 | (diff-end-of-file) |
| 537 | (if (looking-at "^\n") (forward-char 1)) ;`tla' generates such diffs. | 552 | (if (looking-at "^\n") (forward-char 1)) ;`tla' generates such diffs. |
| 553 | (if (> orig (point)) (error "Not inside a file diff")) | ||
| 538 | (kill-region start (point)))) | 554 | (kill-region start (point)))) |
| 539 | 555 | ||
| 540 | (defun diff-kill-junk () | 556 | (defun diff-kill-junk () |