* 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
+2012-04-25 Chong Yidong <cyd@gnu.org>
+
+ * vc/diff-mode.el (diff-setup-whitespace): New function.
+ (diff-mode): Use it.
+
+ * vc/diff.el (diff-sentinel):
+ * vc/vc.el (vc-diff-finish): Call diff-setup-whitespace to assign
+ Whitespace mode variables based on diff style (Bug#8612).
+
2012-04-25 Leo Liu <sdl.web@gmail.com>
* files.el (auto-mode-alist): Use javascript-mode instead.
(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
;;; 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
;;; Code:
+(declare-function diff-setup-whitespace "diff-mode" ())
+
(eval-when-compile (require 'cl))
(defgroup diff nil
delete the temporary files so named."
(if old-temp-file (delete-file old-temp-file))
(if new-temp-file (delete-file new-temp-file))
+ (diff-setup-whitespace)
(save-excursion
(goto-char (point-max))
(let ((inhibit-read-only t))
(require 'vc-dispatcher)
(require 'ediff)
+(declare-function diff-setup-whitespace "diff-mode" ())
+
(eval-when-compile
(require 'cl)
(require 'dired))
;; possibility of an empty output is for an async process.
(when (buffer-live-p buffer)
(let ((window (get-buffer-window buffer t))
- (emptyp (zerop (buffer-size buffer))))
+ (emptyp (zerop (buffer-size buffer))))
(with-current-buffer buffer
- (and messages emptyp
- (let ((inhibit-read-only t))
- (insert (cdr messages) ".\n")
- (message "%s" (cdr messages))))
- (goto-char (point-min))
- (when window
- (shrink-window-if-larger-than-buffer window)))
+ (and messages emptyp
+ (let ((inhibit-read-only t))
+ (insert (cdr messages) ".\n")
+ (message "%s" (cdr messages))))
+ (diff-setup-whitespace)
+ (goto-char (point-min))
+ (when window
+ (shrink-window-if-larger-than-buffer window)))
(when (and messages (not emptyp))
- (message "%sdone" (car messages))))))
+ (message "%sdone" (car messages))))))
(defvar vc-diff-added-files nil
"If non-nil, diff added files by comparing them to /dev/null.")