unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Andrea Crotti <andrea.crotti.0@gmail.com>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: diff-autosaved
Date: Sat, 30 Apr 2011 12:30:41 +0200	[thread overview]
Message-ID: <sa0r58kt4j2.fsf@gmail.com> (raw)
In-Reply-To: <4DBBCEE7.8030000@easy-emacs.de>

Andreas Röhler <andreas.roehler@easy-emacs.de> 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 24.0.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.22.0)
 of 2011-04-22 on plaetekopp



      parent reply	other threads:[~2011-04-30 10:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-30  8:57 diff-autosaved Andreas Röhler
2011-04-30  9:48 ` diff-autosaved Andrea Crotti
2011-04-30 10:03   ` diff-autosaved Andreas Röhler
2011-04-30 10:31     ` diff-autosaved Andrea Crotti
2011-04-30 10:30 ` Andrea Crotti [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sa0r58kt4j2.fsf@gmail.com \
    --to=andrea.crotti.0@gmail.com \
    --cc=andreas.roehler@easy-emacs.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).