]> code.delx.au - gnu-emacs/blobdiff - lisp/vc/diff-mode.el
Merge from emacs-23; up to 2010-06-11T14:39:54Z!cyd@stupidchicken.com.
[gnu-emacs] / lisp / vc / diff-mode.el
similarity index 96%
rename from lisp/diff-mode.el
rename to lisp/vc/diff-mode.el
index b37c0802033076e07aab9733f021ae0bf14d63f0..56ebe868a2d7424b34d52262f49f8dae57a26f6c 100644 (file)
@@ -1,10 +1,9 @@
-;;; diff-mode.el --- a mode for viewing/editing context diffs
+;;; diff-mode.el --- a mode for viewing/editing context diffs -*- lexical-binding: t -*-
 
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,2005, 2006,
-;;   2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
+;; Copyright (C) 1998-2011  Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
-;; Keywords: convenience patch diff
+;; Keywords: convenience patch diff vc
 
 ;; This file is part of GNU Emacs.
 
@@ -123,8 +122,7 @@ when editing big diffs)."
     ("\C-m" . diff-goto-source)
     ([mouse-2] . diff-goto-source)
     ;; From XEmacs' diff-mode.
-    ;; Standard M-w is useful, so don't change M-W.
-    ;;("W" . widen)
+    ("W" . widen)
     ;;("." . diff-goto-source)         ;display-buffer
     ;;("f" . diff-goto-source)         ;find-file
     ("o" . diff-goto-source)           ;other-window
@@ -136,17 +134,21 @@ when editing big diffs)."
     ;; Not useful if you have to metafy them.
     ;;(" " . scroll-up)
     ;;("\177" . scroll-down)
-    ;; Standard M-a is useful, so don't change M-A.
-    ;;("A" . diff-ediff-patch)
-    ;; Standard M-r is useful, so don't change M-r or M-R.
-    ;;("r" . diff-restrict-view)
-    ;;("R" . diff-reverse-direction)
-    ("g" . revert-buffer)
-    ("q" . quit-window))
-  "Basic keymap for `diff-mode', bound to various prefix keys.")
+    ("A" . diff-ediff-patch)
+    ("r" . diff-restrict-view)
+    ("R" . diff-reverse-direction))
+  "Basic keymap for `diff-mode', bound to various prefix keys."
+  :inherit special-mode-map)
 
 (easy-mmode-defmap diff-mode-map
-  `(("\e" . ,diff-mode-shared-map)
+  `(("\e" . ,(let ((map (make-sparse-keymap)))
+               ;; We want to inherit most bindings from diff-mode-shared-map,
+               ;; but not all since they may hide useful M-<foo> global
+               ;; bindings when editing.
+               (set-keymap-parent map diff-mode-shared-map)
+               (dolist (key '("A" "r" "R" "g" "q" "W"))
+                 (define-key map key nil))
+               map))
     ;; From compilation-minor-mode.
     ("\C-c\C-c" . diff-goto-source)
     ;; By analogy with the global C-x 4 a binding.
@@ -812,7 +814,7 @@ PREFIX is only used internally: don't use it."
 (defun diff-ediff-patch ()
   "Call `ediff-patch-file' on the current buffer."
   (interactive)
-  (condition-case err
+  (condition-case nil
       (ediff-patch-file nil (current-buffer))
     (wrong-number-of-arguments (ediff-patch-file))))
 
@@ -1171,7 +1173,7 @@ else cover the whole buffer."
 ;; *-change-function is asking for trouble, whereas making them
 ;; from a post-command-hook doesn't pose much problems
 (defvar diff-unhandled-changes nil)
-(defun diff-after-change-function (beg end len)
+(defun diff-after-change-function (beg end _len)
   "Remember to fixup the hunk header.
 See `after-change-functions' for the meaning of BEG, END and LEN."
   ;; Ignoring changes when inhibit-read-only is set is strictly speaking
@@ -1269,7 +1271,7 @@ a diff with \\[diff-reverse-direction].
 
   ;; 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-style) '(face trailing))
   (set (make-local-variable 'whitespace-trailing-regexp)
        "^[-\+!<>].*?\\([\t ]+\\)$")
 
@@ -1281,7 +1283,7 @@ a diff with \\[diff-reverse-direction].
     (add-hook 'after-change-functions 'diff-after-change-function nil t)
     (add-hook 'post-command-hook 'diff-post-command-hook nil t))
   ;; Neat trick from Dave Love to add more bindings in read-only mode:
-  (lexical-let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
+  (let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
     (add-to-list 'minor-mode-overriding-map-alist ro-bind)
     ;; Turn off this little trick in case the buffer is put in view-mode.
     (add-hook 'view-mode-hook
@@ -1293,7 +1295,9 @@ a diff with \\[diff-reverse-direction].
   (set (make-local-variable 'add-log-current-defun-function)
        'diff-current-defun)
   (set (make-local-variable 'add-log-buffer-file-name-function)
-       (lambda () (diff-find-file-name nil 'noprompt))))
+       (lambda () (diff-find-file-name nil 'noprompt)))
+  (unless (buffer-file-name)
+    (hack-dir-local-variables-non-file-buffer)))
 
 ;;;###autoload
 (define-minor-mode diff-minor-mode
@@ -1691,7 +1695,7 @@ With a prefix argument, REVERSE the hunk."
   "See whether it's possible to apply the current hunk.
 With a prefix argument, try to REVERSE the hunk."
   (interactive "P")
-  (destructuring-bind (buf line-offset pos src dst &optional switched)
+  (destructuring-bind (buf line-offset pos src _dst &optional switched)
       (diff-find-source-location nil reverse)
     (set-window-point (display-buffer buf) (+ (car pos) (cdr src)))
     (diff-hunk-status-msg line-offset (diff-xor reverse switched) t)))
@@ -1711,7 +1715,7 @@ then `diff-jump-to-old-file' is also set, for the next invocations."
   ;; This is a convenient detail when using smerge-diff.
   (if event (posn-set-point (event-end event)))
   (let ((rev (not (save-excursion (beginning-of-line) (looking-at "[-<]")))))
-    (destructuring-bind (buf line-offset pos src dst &optional switched)
+    (destructuring-bind (buf line-offset pos src _dst &optional switched)
        (diff-find-source-location other-file rev)
       (pop-to-buffer buf)
       (goto-char (+ (car pos) (cdr src)))
@@ -1729,7 +1733,7 @@ For use in `add-log-current-defun-function'."
     (when (looking-at diff-hunk-header-re)
       (forward-line 1)
       (re-search-forward "^[^ ]" nil t))
-    (destructuring-bind (&optional buf line-offset pos src dst switched)
+    (destructuring-bind (&optional buf _line-offset pos src dst switched)
         ;; Use `noprompt' since this is used in which-func-mode and such.
        (ignore-errors                ;Signals errors in place of prompting.
           (diff-find-source-location nil nil 'noprompt))
@@ -1823,10 +1827,13 @@ For use in `add-log-current-defun-function'."
     (replace-match (cdr (assq (char-before) '((?+ . "-") (?> . "<"))))))
   )
 
+(declare-function smerge-refine-subst "smerge-mode"
+                  (beg1 end1 beg2 end2 props &optional preproc))
+
 (defun diff-refine-hunk ()
   "Highlight changes of hunk at point at a finer granularity."
   (interactive)
-  (eval-and-compile (require 'smerge-mode))
+  (require 'smerge-mode)
   (save-excursion
     (diff-beginning-of-hunk 'try-harder)
     (let* ((start (point))
@@ -1877,28 +1884,27 @@ I.e. like `add-change-log-entry-other-window' but applied to all hunks."
   ;; good to call it for each change.
   (save-excursion
     (goto-char (point-min))
-    (let ((orig-buffer (current-buffer)))
-      (condition-case nil
-         ;; Call add-change-log-entry-other-window for each hunk in
-         ;; the diff buffer.
-         (while (progn
-                   (diff-hunk-next)
-                   ;; Move to where the changes are,
-                   ;; `add-change-log-entry-other-window' works better in
-                   ;; that case.
-                   (re-search-forward
-                    (concat "\n[!+-<>]"
-                            ;; If the hunk is a context hunk with an empty first
-                            ;; half, recognize the "--- NNN,MMM ----" line
-                            "\\(-- [0-9]+\\(,[0-9]+\\)? ----\n"
-                            ;; and skip to the next non-context line.
-                            "\\( .*\n\\)*[+]\\)?")
-                    nil t))
-            (save-excursion
-              ;; FIXME: this pops up windows of all the buffers.
-              (add-change-log-entry nil nil t nil t)))
-        ;; When there's no more hunks, diff-hunk-next signals an error.
-       (error nil)))))
+    (condition-case nil
+        ;; Call add-change-log-entry-other-window for each hunk in
+        ;; the diff buffer.
+        (while (progn
+                 (diff-hunk-next)
+                 ;; Move to where the changes are,
+                 ;; `add-change-log-entry-other-window' works better in
+                 ;; that case.
+                 (re-search-forward
+                  (concat "\n[!+-<>]"
+                          ;; If the hunk is a context hunk with an empty first
+                          ;; half, recognize the "--- NNN,MMM ----" line
+                          "\\(-- [0-9]+\\(,[0-9]+\\)? ----\n"
+                          ;; and skip to the next non-context line.
+                          "\\( .*\n\\)*[+]\\)?")
+                  nil t))
+          (save-excursion
+            ;; FIXME: this pops up windows of all the buffers.
+            (add-change-log-entry nil nil t nil t)))
+      ;; When there's no more hunks, diff-hunk-next signals an error.
+      (error nil))))
 
 ;; provide the package
 (provide 'diff-mode)
@@ -1938,5 +1944,4 @@ I.e. like `add-change-log-entry-other-window' but applied to all hunks."
 ;; use `combine-after-change-calls' to minimize the slowdown of font-lock.
 ;;
 
-;; arch-tag: 2571d7ff-bc28-4cf9-8585-42e21890be66
 ;;; diff-mode.el ends here