summaryrefslogtreecommitdiff
path: root/lisp/diff-mode.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2008-02-19 21:31:20 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2008-02-19 21:31:20 +0000
commitdc09b73f0371da04266e2dc4dee9790cfb96e34c (patch)
tree92e812c8f7687237b49b8305aa1bcaf791573dd6 /lisp/diff-mode.el
parent7ebb6e4b749c66a460d4253318633e17688d2332 (diff)
downloademacs-dc09b73f0371da04266e2dc4dee9790cfb96e34c.tar.gz
(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.el26
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."
(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 @@ data such as \"Index: ...\" and such."
(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 ()