-;;; diff.el --- run `diff'
+;;; diff.el --- run `diff' -*- lexical-binding: t -*-
-;; Copyright (C) 1992, 1994, 1996, 2001-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 1994, 1996, 2001-2015 Free Software Foundation,
+;; Inc.
;; Author: Frank Bresz
;; (according to authors.el)
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
;; Keywords: unix, vc, tools
;; This file is part of GNU Emacs.
;;; Code:
-(eval-when-compile (require 'cl))
+(declare-function diff-setup-whitespace "diff-mode" ())
(defgroup diff nil
"Comparing files with `diff'."
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))
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."
+specified in the variable `diff-switches' are passed to the diff command."
(interactive
(let* ((newf (if (and buffer-file-name (file-exists-p buffer-file-name))
(read-file-name
tempfile))
(file-local-copy file-or-buf)))
+(defvar diff-use-labels 'check
+ "Whether `diff-command' understands the \"--label\" option.
+Possible values are:
+ t -- yes, it does
+ nil -- no, it does not
+ check -- try to probe whether it does")
+
(defun diff-no-select (old new &optional switches no-async buf)
;; Noninteractive helper for creating and reverting diff buffers
(unless (bufferp new) (setq new (expand-file-name new)))
(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*")))
+ (when (eq 'check diff-use-labels)
+ (setq diff-use-labels
+ (with-temp-buffer
+ (when (ignore-errors (call-process diff-command nil t nil "--help"))
+ (if (search-backward "--label" nil t) t)))))
(let* ((old-alt (diff-file-local-copy old))
(new-alt (diff-file-local-copy new))
(command
,@switches
,@(mapcar #'shell-quote-argument
(nconc
- (when (or old-alt new-alt)
- (list "-L" (if (stringp old)
- old (prin1-to-string old))
- "-L" (if (stringp new)
- new (prin1-to-string new))))
+ (and (or old-alt new-alt)
+ (eq diff-use-labels t)
+ (list "--label"
+ (if (stringp old) old
+ (prin1-to-string old))
+ "--label"
+ (if (stringp new) new
+ (prin1-to-string new))))
(list (or old-alt old)
(or new-alt new)))))
" "))
(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"))
(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
ori file))
(diff bak ori switches)))
-(defun diff-latest-backup-file (fn) ; actually belongs into files.el
+;;;###autoload
+(defun diff-latest-backup-file (fn)
"Return the latest existing backup of FILE, or nil."
(let ((handler (find-file-name-handler fn 'diff-latest-backup-file)))
(if handler