Remove incorrect uses of "modeline".
[bpt/emacs.git] / lisp / vc / diff.el
index 13c23ee..6cfee52 100644 (file)
@@ -1,7 +1,6 @@
-;;; diff.el --- run `diff' in compilation-mode
+;;; diff.el --- run `diff'  -*- lexical-binding: t -*-
 
-;; Copyright (C) 1992, 1994, 1996, 2001, 2002, 2003, 2004, 2005, 2006,
-;;   2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 1994, 1996, 2001-2012 Free Software Foundation, Inc.
 
 ;; Author: Frank Bresz
 ;; (according to authors.el)
@@ -31,6 +30,8 @@
 
 ;;; Code:
 
+(declare-function diff-setup-whitespace "diff-mode" ())
+
 (eval-when-compile (require 'cl))
 
 (defgroup diff nil
                       diff-switches
                     (mapconcat 'identity diff-switches " ")))))
 
-(defun diff-sentinel (code old-temp-file new-temp-file)
+(defun diff-sentinel (code &optional old-temp-file new-temp-file)
   "Code run when the diff process exits.
 CODE is the exit code of the process.  It should be 0 only if no diffs
-were found."
+were found.
+If optional args OLD-TEMP-FILE and/or NEW-TEMP-FILE are non-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)
+  (goto-char (point-min))
   (save-excursion
     (goto-char (point-max))
     (let ((inhibit-read-only t))
@@ -75,23 +80,22 @@ were found."
 ;;;###autoload
 (defun diff (old new &optional switches no-async)
   "Find and display the differences between OLD and NEW files.
-When called interactively, read OLD and NEW using the minibuffer;
-the default for NEW is the current buffer's file name, and the
-default for OLD is a backup file for NEW, if one exists.
-If NO-ASYNC is non-nil, call diff synchronously.
+When called interactively, read NEW, then OLD, using the
+minibuffer.  The default for NEW is the current buffer's file
+name, and the default for OLD is a backup file for NEW, if one
+exists.  If NO-ASYNC is non-nil, call diff synchronously.
 
 When called interactively with a prefix argument, prompt
 interactively for diff switches.  Otherwise, the switches
 specified in `diff-switches' are passed to the diff command."
   (interactive
-   (let* ((newf (buffer-file-name))
-          (oldf (file-newest-backup newf)))
-     (setq newf (if (and newf (file-exists-p newf))
+   (let* ((newf (if (and buffer-file-name (file-exists-p buffer-file-name))
                    (read-file-name
                     (concat "Diff new file (default "
-                            (file-name-nondirectory newf) "): ")
-                    nil newf t)
+                            (file-name-nondirectory buffer-file-name) "): ")
+                    nil buffer-file-name t)
                  (read-file-name "Diff new file: " nil nil t)))
+          (oldf (file-newest-backup newf)))
      (setq oldf (if (and oldf (file-exists-p oldf))
                    (read-file-name
                     (concat "Diff original file (default "
@@ -111,18 +115,10 @@ specified in `diff-switches' are passed to the diff command."
           tempfile))
     (file-local-copy file-or-buf)))
 
-(defun diff-better-file-name (file)
-  (if (bufferp file) file
-    (let ((rel (file-relative-name file))
-          (abbr (abbreviate-file-name (expand-file-name file))))
-      (if (< (length abbr) (length rel))
-          abbr
-        rel))))
-
 (defun diff-no-select (old new &optional switches no-async buf)
   ;; Noninteractive helper for creating and reverting diff buffers
-  (setq new (diff-better-file-name new)
-       old (diff-better-file-name old))
+  (unless (bufferp new) (setq new (expand-file-name new)))
+  (unless (bufferp old) (setq old (expand-file-name old)))
   (or switches (setq switches diff-switches)) ; If not specified, use default.
   (unless (listp switches) (setq switches (list switches)))
   (or buf (setq buf (get-buffer-create "*Diff*")))
@@ -152,11 +148,8 @@ specified in `diff-switches' are passed to the diff command."
       (buffer-enable-undo (current-buffer))
       (diff-mode)
       (set (make-local-variable 'revert-buffer-function)
-           (lexical-let ((old old) (new new)
-                         (switches switches)
-                         (no-async no-async))
-             (lambda (ignore-auto noconfirm)
-               (diff-no-select old new switches no-async (current-buffer)))))
+           (lambda (_ignore-auto _noconfirm)
+             (diff-no-select old new switches no-async (current-buffer))))
       (setq default-directory thisdir)
       (let ((inhibit-read-only t))
        (insert command "\n"))
@@ -164,12 +157,11 @@ specified in `diff-switches' are passed to the diff command."
          (let ((proc (start-process "Diff" buf shell-file-name
                                      shell-command-switch command)))
            (set-process-filter proc 'diff-process-filter)
-            (lexical-let ((old-alt old-alt) (new-alt new-alt))
-              (set-process-sentinel
-               proc (lambda (proc msg)
-                      (with-current-buffer (process-buffer proc)
-                        (diff-sentinel (process-exit-status proc)
-                                       old-alt new-alt))))))
+            (set-process-sentinel
+             proc (lambda (proc _msg)
+                    (with-current-buffer (process-buffer proc)
+                      (diff-sentinel (process-exit-status proc)
+                                     old-alt new-alt)))))
        ;; Async processes aren't available.
        (let ((inhibit-read-only t))
          (diff-sentinel
@@ -224,5 +216,4 @@ This requires the external program `diff' to be in your `exec-path'."
 
 (provide 'diff)
 
-;; arch-tag: 7de2c29b-7ea5-4b85-9b9d-72dd860de2bd
 ;;; diff.el ends here