diff options
author | Chong Yidong <cyd@gnu.org> | 2012-04-25 23:06:51 +0800 |
---|---|---|
committer | Chong Yidong <cyd@gnu.org> | 2012-04-25 23:06:51 +0800 |
commit | 07875ee72bffac01a1978d0367883d6ceb88cc55 (patch) | |
tree | e0815f89a1b9d015e0fdbde6670bec3aeef74096 /lisp/vc/diff-mode.el | |
parent | 5055880d396c98f9bacfd4d19aa4a9ae85d3a87c (diff) | |
download | emacs-07875ee72bffac01a1978d0367883d6ceb88cc55.tar.gz |
Fix whitespace highlighting of context diffs.
* lisp/vc/diff-mode.el (diff-setup-whitespace): New function.
(diff-mode): Use it.
* lisp/vc/diff.el (diff-sentinel):
* lisp/vc/vc.el (vc-diff-finish): Call diff-setup-whitespace to assign
Whitespace mode variables based on diff style.
Fixes: debbugs:8612
Diffstat (limited to 'lisp/vc/diff-mode.el')
-rw-r--r-- | lisp/vc/diff-mode.el | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 8b6b85dd22e..c92371fc90b 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -1283,11 +1283,7 @@ a diff with \\[diff-reverse-direction]. (set (make-local-variable 'end-of-defun-function) 'diff-end-of-file) - ;; Set up `whitespace-mode' so that turning it on will show trailing - ;; whitespace problems on the modified lines of the diff. - (set (make-local-variable 'whitespace-style) '(face trailing)) - (set (make-local-variable 'whitespace-trailing-regexp) - "^[-\+!<>].*?\\([\t ]+\\)$") + (diff-setup-whitespace) (setq buffer-read-only diff-default-read-only) ;; setup change hooks @@ -1332,6 +1328,22 @@ the mode if ARG is omitted or nil. ;;; Handy hook functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun diff-setup-whitespace () + "Set up Whitespace mode variables for the current Diff mode buffer. +This sets `whitespace-style' and `whitespace-trailing-regexp' so +that Whitespace mode shows trailing whitespace problems on the +modified lines of the diff." + (set (make-local-variable 'whitespace-style) '(face trailing)) + (let ((style (save-excursion + (goto-char (point-min)) + (when (re-search-forward diff-hunk-header-re nil t) + (goto-char (match-beginning 0)) + (diff-hunk-style))))) + (set (make-local-variable 'whitespace-trailing-regexp) + (if (eq style 'context) + "^[-\+!] .*?\\([\t ]+\\)$" + "^[-\+!<>].*?\\([\t ]+\\)$")))) + (defun diff-delete-if-empty () ;; An empty diff file means there's no more diffs to integrate, so we ;; can just remove the file altogether. Very handy for .rej files if we |