aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-04-25 23:06:51 +0800
committerChong Yidong2012-04-25 23:06:51 +0800
commit07875ee72bffac01a1978d0367883d6ceb88cc55 (patch)
treee0815f89a1b9d015e0fdbde6670bec3aeef74096
parent5055880d396c98f9bacfd4d19aa4a9ae85d3a87c (diff)
downloademacs-07875ee72bffac01a1978d0367883d6ceb88cc55.tar.gz
emacs-07875ee72bffac01a1978d0367883d6ceb88cc55.zip
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
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/vc/diff-mode.el22
-rw-r--r--lisp/vc/diff.el3
-rw-r--r--lisp/vc/vc.el21
4 files changed, 41 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cad73c2e2e7..4ec3b1934a4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12012-04-25 Chong Yidong <cyd@gnu.org>
2
3 * vc/diff-mode.el (diff-setup-whitespace): New function.
4 (diff-mode): Use it.
5
6 * vc/diff.el (diff-sentinel):
7 * vc/vc.el (vc-diff-finish): Call diff-setup-whitespace to assign
8 Whitespace mode variables based on diff style (Bug#8612).
9
12012-04-25 Leo Liu <sdl.web@gmail.com> 102012-04-25 Leo Liu <sdl.web@gmail.com>
2 11
3 * files.el (auto-mode-alist): Use javascript-mode instead. 12 * files.el (auto-mode-alist): Use javascript-mode instead.
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].
1283 (set (make-local-variable 'end-of-defun-function) 1283 (set (make-local-variable 'end-of-defun-function)
1284 'diff-end-of-file) 1284 'diff-end-of-file)
1285 1285
1286 ;; Set up `whitespace-mode' so that turning it on will show trailing 1286 (diff-setup-whitespace)
1287 ;; whitespace problems on the modified lines of the diff.
1288 (set (make-local-variable 'whitespace-style) '(face trailing))
1289 (set (make-local-variable 'whitespace-trailing-regexp)
1290 "^[-\+!<>].*?\\([\t ]+\\)$")
1291 1287
1292 (setq buffer-read-only diff-default-read-only) 1288 (setq buffer-read-only diff-default-read-only)
1293 ;; setup change hooks 1289 ;; setup change hooks
@@ -1332,6 +1328,22 @@ the mode if ARG is omitted or nil.
1332 1328
1333;;; Handy hook functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1329;;; Handy hook functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1334 1330
1331(defun diff-setup-whitespace ()
1332 "Set up Whitespace mode variables for the current Diff mode buffer.
1333This sets `whitespace-style' and `whitespace-trailing-regexp' so
1334that Whitespace mode shows trailing whitespace problems on the
1335modified lines of the diff."
1336 (set (make-local-variable 'whitespace-style) '(face trailing))
1337 (let ((style (save-excursion
1338 (goto-char (point-min))
1339 (when (re-search-forward diff-hunk-header-re nil t)
1340 (goto-char (match-beginning 0))
1341 (diff-hunk-style)))))
1342 (set (make-local-variable 'whitespace-trailing-regexp)
1343 (if (eq style 'context)
1344 "^[-\+!] .*?\\([\t ]+\\)$"
1345 "^[-\+!<>].*?\\([\t ]+\\)$"))))
1346
1335(defun diff-delete-if-empty () 1347(defun diff-delete-if-empty ()
1336 ;; An empty diff file means there's no more diffs to integrate, so we 1348 ;; An empty diff file means there's no more diffs to integrate, so we
1337 ;; can just remove the file altogether. Very handy for .rej files if we 1349 ;; can just remove the file altogether. Very handy for .rej files if we
diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el
index 05208894356..dd4b4757e88 100644
--- a/lisp/vc/diff.el
+++ b/lisp/vc/diff.el
@@ -30,6 +30,8 @@
30 30
31;;; Code: 31;;; Code:
32 32
33(declare-function diff-setup-whitespace "diff-mode" ())
34
33(eval-when-compile (require 'cl)) 35(eval-when-compile (require 'cl))
34 36
35(defgroup diff nil 37(defgroup diff nil
@@ -64,6 +66,7 @@ If optional args OLD-TEMP-FILE and/or NEW-TEMP-FILE are non-nil,
64delete the temporary files so named." 66delete the temporary files so named."
65 (if old-temp-file (delete-file old-temp-file)) 67 (if old-temp-file (delete-file old-temp-file))
66 (if new-temp-file (delete-file new-temp-file)) 68 (if new-temp-file (delete-file new-temp-file))
69 (diff-setup-whitespace)
67 (save-excursion 70 (save-excursion
68 (goto-char (point-max)) 71 (goto-char (point-max))
69 (let ((inhibit-read-only t)) 72 (let ((inhibit-read-only t))
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 9ca9e00b8af..433383502da 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -655,6 +655,8 @@
655(require 'vc-dispatcher) 655(require 'vc-dispatcher)
656(require 'ediff) 656(require 'ediff)
657 657
658(declare-function diff-setup-whitespace "diff-mode" ())
659
658(eval-when-compile 660(eval-when-compile
659 (require 'cl) 661 (require 'cl)
660 (require 'dired)) 662 (require 'dired))
@@ -1524,17 +1526,18 @@ to override the value of `vc-diff-switches' and `diff-switches'."
1524 ;; possibility of an empty output is for an async process. 1526 ;; possibility of an empty output is for an async process.
1525 (when (buffer-live-p buffer) 1527 (when (buffer-live-p buffer)
1526 (let ((window (get-buffer-window buffer t)) 1528 (let ((window (get-buffer-window buffer t))
1527 (emptyp (zerop (buffer-size buffer)))) 1529 (emptyp (zerop (buffer-size buffer))))
1528 (with-current-buffer buffer 1530 (with-current-buffer buffer
1529 (and messages emptyp 1531 (and messages emptyp
1530 (let ((inhibit-read-only t)) 1532 (let ((inhibit-read-only t))
1531 (insert (cdr messages) ".\n") 1533 (insert (cdr messages) ".\n")
1532 (message "%s" (cdr messages)))) 1534 (message "%s" (cdr messages))))
1533 (goto-char (point-min)) 1535 (diff-setup-whitespace)
1534 (when window 1536 (goto-char (point-min))
1535 (shrink-window-if-larger-than-buffer window))) 1537 (when window
1538 (shrink-window-if-larger-than-buffer window)))
1536 (when (and messages (not emptyp)) 1539 (when (and messages (not emptyp))
1537 (message "%sdone" (car messages)))))) 1540 (message "%sdone" (car messages))))))
1538 1541
1539(defvar vc-diff-added-files nil 1542(defvar vc-diff-added-files nil
1540 "If non-nil, diff added files by comparing them to /dev/null.") 1543 "If non-nil, diff added files by comparing them to /dev/null.")