[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: diff-autosaved

From: Andrea Crotti
Subject: Re: diff-autosaved
Date: Sat, 30 Apr 2011 12:30:41 +0200
User-agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux)

Andreas Röhler <address@hidden> writes:

> Hi,
> occassionally want to compare a file with its auto-saved version.
> Couldn't find a function doing this.
> Tweaked diff-backup for the purpose.
> The result:
> (defun diff-autosaved (&optional switches)
>   "Diff this file with its auto-saved version or vice versa.
> With prefix arg, prompt for diff switches."
>   (interactive (list (diff-switches)))
>   (let ((dir default-directory)
>         (file (file-name-nondirectory (replace-regexp-in-string "#" ""
> (buffer-file-name))))
>         bak ori)
>     (if (string-match "^#" file)
>       (setq bak file
>             ori (replace-regexp-in-string "#" "" file))
>       (setq bak (concat "#" file "#")
>             ori file))
>     (setq bak (concat dir bak))
>     (setq ori (concat dir ori))
>     (diff bak ori switches)))
> Comments welcome.
> Andreas

Anyway there is a function to generate the file name of the backup file,
now it looks for a strange path in .emacs.d but well I think it depends
on the setting.

--8<---------------cut here---------------start------------->8---
(defun diff-autosaved2 (&optional switches)
  (interactive (list (diff-switches)))
  (let ((bk-file (make-backup-file-name (buffer-file-name))))
    (if (file-exists-p bk-file)
      (diff (buffer-file-name) bk-file)
      (message (format "Backup file %s not found" bk-file)))))
--8<---------------cut here---------------end--------------->8---

GNU Emacs (x86_64-unknown-linux-gnu, GTK+ Version 2.22.0)
 of 2011-04-22 on plaetekopp

reply via email to

[Prev in Thread] Current Thread [Next in Thread]