]> code.delx.au - gnu-emacs/blobdiff - lisp/diff-mode.el
(doc-view-scroll-up-or-next-page)
[gnu-emacs] / lisp / diff-mode.el
index b711b0635d67f53c2b53b258a20c2a5c63a7cd62..a83200d8982835a0e27194c51a7d889bd6bf0abc 100644 (file)
@@ -1,7 +1,7 @@
 ;;; diff-mode.el --- a mode for viewing/editing context diffs
 
 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; Keywords: convenience patch diff
@@ -39,7 +39,7 @@
 
 ;; - Improve `diff-add-change-log-entries-other-window',
 ;;   it is very simplistic now.
-;;  
+;;
 ;; - Add a `delete-after-apply' so C-c C-a automatically deletes hunks.
 ;;   Also allow C-c C-a to delete already-applied hunks.
 ;;
@@ -77,7 +77,7 @@ Else, it jumps to the new file."
   :group 'diff-mode)
 
 (defcustom diff-update-on-the-fly t
-  "*Non-nil means hunk headers are kept up-to-date on-the-fly.
+  "Non-nil means hunk headers are kept up-to-date on-the-fly.
 When editing a diff file, the line numbers in the hunk headers
 need to be kept consistent with the actual diff.  This can
 either be done on the fly (but this sometimes interacts poorly with the
@@ -87,7 +87,7 @@ when editing big diffs)."
   :group 'diff-mode)
 
 (defcustom diff-advance-after-apply-hunk t
-  "*Non-nil means `diff-apply-hunk' will move to the next hunk after applying."
+  "Non-nil means `diff-apply-hunk' will move to the next hunk after applying."
   :type 'boolean
   :group 'diff-mode)
 
@@ -183,6 +183,9 @@ when editing big diffs)."
     ["Unified -> Context"      diff-unified->context
      :help "Convert unified diffs to context diffs"]
     ;;["Fixup Headers"         diff-fixup-modifs       (not buffer-read-only)]
+    ["Show trailing whitespace" whitespace-mode
+     :style toggle :selected (bound-and-true-p whitespace-mode)
+     :help "Show trailing whitespace in modified lines"]
     "-----"
     ["Split hunk"              diff-split-hunk
      :active (diff-splittable-p)
@@ -517,7 +520,7 @@ but in the file header instead, in which case move forward to the first hunk."
           res
         (goto-char start)
         (error "Can't find the beginning of the file")))))
-        
+
 
 (defun diff-end-of-file ()
   (re-search-forward "^[-+#!<>0-9@* \\]" nil t)
@@ -571,7 +574,7 @@ If the prefix ARG is given, restrict the view to the current file instead."
 
 ;; "index ", "old mode", "new mode", "new file mode" and
 ;; "deleted file mode" are output by git-diff.
-(defconst diff-file-junk-re 
+(defconst diff-file-junk-re
   "diff \\|index \\|\\(?:deleted file\\|new\\(?: file\\)?\\|old\\) mode")
 
 (defun diff-beginning-of-file-and-junk ()
@@ -620,7 +623,7 @@ data such as \"Index: ...\" and such."
       ;; a file diff but elsewhere.
       (goto-char orig)
       (signal (car err) (cdr err)))))
-          
+
 (defun diff-file-kill ()
   "Kill current file's hunks."
   (interactive)
@@ -1227,6 +1230,9 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
   (diff-hunk-next arg)
   (diff-goto-source))
 
+(defvar whitespace-style)
+(defvar whitespace-trailing-regexp)
+
 ;;;###autoload
 (define-derived-mode diff-mode fundamental-mode "Diff"
   "Major mode for viewing/editing context diffs.
@@ -1264,6 +1270,12 @@ 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) '(trailing))
+  (set (make-local-variable 'whitespace-trailing-regexp)
+       "^[-\+!<>].*?\\([\t ]+\\)$")
+
   (setq buffer-read-only diff-default-read-only)
   ;; setup change hooks
   (if (not diff-update-on-the-fly)
@@ -1635,7 +1647,7 @@ With a prefix argument, REVERSE the hunk."
       ;; for diff-goto-source, and is thus confusing.  Also when you don't
       ;; know about it it's pretty surprising.
       ;; TODO: make it possible to ask explicitly for this behavior.
-      ;; 
+      ;;
       ;; This is duplicated in diff-test-hunk.
       (diff-find-source-location nil reverse)
     (cond
@@ -1885,13 +1897,6 @@ I.e. like `add-change-log-entry-other-window' but applied to all hunks."
         ;; When there's no more hunks, diff-hunk-next signals an error.
        (error nil)))))
 
-(defun diff-show-trailing-whitespaces ()
-  "Show trailing whitespaces in modified lines for diff-mode."
-  (interactive)
-  (let ((whitespace-style '(trailing))
-        (whitespace-trailing-regexp "^[-\+!<>].*?\\([\t ]+\\)$"))
-    (whitespace-mode 1)))     ; display trailing whitespace in diff buffer
-
 ;; provide the package
 (provide 'diff-mode)