all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* diff-autosaved
@ 2011-04-30  8:57 Andreas Röhler
  2011-04-30  9:48 ` diff-autosaved Andrea Crotti
  2011-04-30 10:30 ` diff-autosaved Andrea Crotti
  0 siblings, 2 replies; 5+ messages in thread
From: Andreas Röhler @ 2011-04-30  8:57 UTC (permalink / raw
  To: help-gnu-emacs

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

--
https://code.launchpad.net/~a-roehler/python-mode/components-python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: diff-autosaved
  2011-04-30  8:57 diff-autosaved Andreas Röhler
@ 2011-04-30  9:48 ` Andrea Crotti
  2011-04-30 10:03   ` diff-autosaved Andreas Röhler
  2011-04-30 10:30 ` diff-autosaved Andrea Crotti
  1 sibling, 1 reply; 5+ messages in thread
From: Andrea Crotti @ 2011-04-30  9:48 UTC (permalink / raw
  To: Andreas Röhler; +Cc: help-gnu-emacs

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

Nice I'll try it out...
But why do you want to compare with the auto-saved, and not for example
do diff-buffer-with-file?

And also using revision control I just see the git/bzr/whatever diff
with the last committed version..

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: diff-autosaved
  2011-04-30  9:48 ` diff-autosaved Andrea Crotti
@ 2011-04-30 10:03   ` Andreas Röhler
  2011-04-30 10:31     ` diff-autosaved Andrea Crotti
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Röhler @ 2011-04-30 10:03 UTC (permalink / raw
  To: Andrea Crotti; +Cc: help-gnu-emacs

Am 30.04.2011 11:48, schrieb Andrea Crotti:
> 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
>
> Nice I'll try it out...
> But why do you want to compare with the auto-saved, and not for example
> do diff-buffer-with-file?

If an auto-saved exists, it means, buffer has not being saved at some time.

diff-buffer-with-file doesn't relate to an existing auto-saved.
It does:

(diff buffer-file-name (current-buffer)...




>
> And also using revision control I just see the git/bzr/whatever diff
> with the last committed version..
>

If a buffer wasn't saved, VC will see no diff.
Just the auto-save exists in this case.

Cheers

Andreas




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: diff-autosaved
  2011-04-30  8:57 diff-autosaved Andreas Röhler
  2011-04-30  9:48 ` diff-autosaved Andrea Crotti
@ 2011-04-30 10:30 ` Andrea Crotti
  1 sibling, 0 replies; 5+ messages in thread
From: Andrea Crotti @ 2011-04-30 10:30 UTC (permalink / raw
  To: Andreas Röhler; +Cc: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: diff-autosaved
  2011-04-30 10:03   ` diff-autosaved Andreas Röhler
@ 2011-04-30 10:31     ` Andrea Crotti
  0 siblings, 0 replies; 5+ messages in thread
From: Andrea Crotti @ 2011-04-30 10:31 UTC (permalink / raw
  To: Andreas Röhler; +Cc: help-gnu-emacs

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

>
> If an auto-saved exists, it means, buffer has not being saved at some time.
>
> diff-buffer-with-file doesn't relate to an existing auto-saved.
> It does:
>
> (diff buffer-file-name (current-buffer)...
>

Yes true, I find myself pressing C-x C-s all the time after I modify
something, even without noticing, so it almost never happens that emacs
crashes AND I didn't save...



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-04-30 10:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` diff-autosaved Andrea Crotti

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.