Mercurial > emacs
changeset 80152:f200e5de5464
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 19 Feb 2008 21:31:20 +0000 |
parents | 533d83b5f687 |
children | 48f9158be833 |
files | lisp/ChangeLog lisp/diff-mode.el |
diffstat | 2 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Tue Feb 19 19:44:48 2008 +0000 +++ b/lisp/ChangeLog Tue Feb 19 21:31:20 2008 +0000 @@ -1,5 +1,9 @@ 2008-02-19 Stefan Monnier <monnier@iro.umontreal.ca> + * diff-mode.el (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. + * diff-mode.el: Make it more robust in the presence of empty context lines in unified hunks. (diff-valid-unified-empty-line): New var.
--- a/lisp/diff-mode.el Tue Feb 19 19:44:48 2008 +0000 +++ b/lisp/diff-mode.el Tue Feb 19 21:31:20 2008 +0000 @@ -501,11 +501,19 @@ (diff-end-of-hunk) (kill-region start (point))))) +(defconst diff-file-junk-re "diff \\|index ") ; "index " is output by git-diff. + (defun diff-beginning-of-file-and-junk () "Go to the beginning of file-related diff-info. This is like `diff-beginning-of-file' except it tries to skip back over leading data such as \"Index: ...\" and such." - (let ((start (point)) + (let ((orig (point)) + ;; Skip forward over what might be "leading junk" so as to get + ;; closer to the actual diff. + (_ (progn (beginning-of-line) + (while (looking-at diff-file-junk-re) + (forward-line 1)))) + (start (point)) (file (condition-case err (progn (diff-beginning-of-file) (point)) (error err))) ;; prevhunk is one of the limits. @@ -521,20 +529,28 @@ (re-search-backward "^Index: " prevhunk t)))) (when index (setq file index)) (if (<= file start) - (goto-char file) + (progn + (goto-char file) + ;; Now skip backward over the leading junk we may have before the + ;; diff itself. + (while (save-excursion + (and (zerop (forward-line -1)) + (looking-at diff-file-junk-re))) + (forward-line -1))) ;; File starts *after* the starting point: we really weren't in ;; a file diff but elsewhere. - (goto-char start) + (goto-char orig) (signal (car err) (cdr err)))))) (defun diff-file-kill () "Kill current file's hunks." (interactive) - (diff-beginning-of-file-and-junk) - (let* ((start (point)) + (let ((orig (point)) + (start (progn (diff-beginning-of-file-and-junk) (point))) (inhibit-read-only t)) (diff-end-of-file) (if (looking-at "^\n") (forward-char 1)) ;`tla' generates such diffs. + (if (> orig (point)) (error "Not inside a file diff")) (kill-region start (point)))) (defun diff-kill-junk ()