;;; 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
;; - 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.
;;
: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
: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)
["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)
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)
;; "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 ()
;; a file diff but elsewhere.
(goto-char orig)
(signal (car err) (cdr err)))))
-
+
(defun diff-file-kill ()
"Kill current file's hunks."
(interactive)
(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.
(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)
;; 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
;; 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)