kj | 29 Aug 2012 14:21

Alerts for saves to non-existent files


It often happens that I move or rename the file "underlying" some
buffer in an ongoing Emacs session and (for various reasons) fail
to make the appropriate change in Emacs, with the result that I
end up inadvertently saving changes to the old location.  This
often leads to unnecessary puzzlement (e.g. changes to an input
file fail to have the expected effects, etc.).

Therefore, I'm looking for a way to have Emacs notice when an
attempt is made to save to a file that no longer exists.  (Of
course, this scenario has to be distinguished somehow from the one
in which the intent is to *create* a file by saving a buffer for
the first time, but maybe it is enough to somehow associate a "first
save" flag with the buffer.)

Is there a way to tell Emacs that, from now on, it should save all
changes to this buffer to the new path (and preferably without
asking for any additional confirmation)?

(As itches go, this one is mild indeed, but it also has a very long
standing, and for this reason alone it has caused, cumulatively
over 3+ decades, a huge amount of vexation.)

Thanks!

Peter Dyballa | 29 Aug 2012 16:54
Picon

Re: Alerts for saves to non-existent files


Am 29.08.2012 um 14:21 schrieb kj:

> Is there a way to tell Emacs that, from now on, it should save all
> changes to this buffer to the new path (and preferably without
> asking for any additional confirmation)?

Write the buffer contents at once to the new location!

--
Greetings

 Pete

Some day we may discover how to make magnets that can point in any direction.

Joost Kremers | 29 Aug 2012 19:04
Picon
Favicon

Re: Alerts for saves to non-existent files

kj wrote:
> Is there a way to tell Emacs that, from now on, it should save all
> changes to this buffer to the new path (and preferably without
> asking for any additional confirmation)?

you can use C-x C-w to save a buffer to another file. that doesn't delete
the original file, but using C-x C-w and then deleting the original file
should cause less vexation than your current scenario. ;-)

--

-- 
Joost Kremers                                      joostkremers <at> yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

kj | 31 Aug 2012 14:35

Re: Alerts for saves to non-existent files

In <slrnk3sit9.dkp.joostkremers <at> j.kremers4.news.arnhem.chello.nl> Joost Kremers
<joostkremers <at> yahoo.com> writes:

>kj wrote:
>> Is there a way to tell Emacs that, from now on, it should save all
>> changes to this buffer to the new path (and preferably without
>> asking for any additional confirmation)?

>you can use C-x C-w to save a buffer to another file. that doesn't delete
>the original file, but using C-x C-w and then deleting the original file
>should cause less vexation than your current scenario. ;-)

No, that doesn't address the problem I tried (but clearly failed)
to describe.  I want to prevent cases in which I *inadvertently*
do C-x C-s, forgetting/not realizing that the current value of
buffer-file-name is a non-existent path.

In fact, I'd be completely satisfied if in such situations Emacs
handled C-x C-s in basically the same way it does for buffers (e.g.
*scratch* or *shell*) whose buffer-file-name is nil, namely by
prompting the user for a "File to save in: ...".  The only difference
between these two cases would be that in the former one, the proposed
path following the prompt would be the (non-existent) path currently
in buffer-file-name, while in the latter it is only directory
prefix, to which the user must add a basename.

Raffaele Ricciardi | 31 Aug 2012 16:19
Picon

Re: Alerts for saves to non-existent files

On 31/08/12 13:35, kj wrote:
> In <slrnk3sit9.dkp.joostkremers <at> j.kremers4.news.arnhem.chello.nl> Joost Kremers
<joostkremers <at> yahoo.com> writes:
>
>> kj wrote:
>>> Is there a way to tell Emacs that, from now on, it should save all
>>> changes to this buffer to the new path (and preferably without
>>> asking for any additional confirmation)?
>
>> you can use C-x C-w to save a buffer to another file. that doesn't delete
>> the original file, but using C-x C-w and then deleting the original file
>> should cause less vexation than your current scenario. ;-)
>
>
> No, that doesn't address the problem I tried (but clearly failed)
> to describe.  I want to prevent cases in which I *inadvertently*
> do C-x C-s, forgetting/not realizing that the current value of
> buffer-file-name is a non-existent path.
>
> In fact, I'd be completely satisfied if in such situations Emacs
> handled C-x C-s in basically the same way it does for buffers (e.g.
> *scratch* or *shell*) whose buffer-file-name is nil, namely by
> prompting the user for a "File to save in: ...".  The only difference
> between these two cases would be that in the former one, the proposed
> path following the prompt would be the (non-existent) path currently
> in buffer-file-name, while in the latter it is only directory
> prefix, to which the user must add a basename.
>

C-h v before-save-hook RET
(Continue reading)

Joost Kremers | 4 Sep 2012 15:59
Picon
Favicon

Re: Alerts for saves to non-existent files

kj wrote:
> In <slrnk3sit9.dkp.joostkremers <at> j.kremers4.news.arnhem.chello.nl> Joost Kremers
<joostkremers <at> yahoo.com> writes:
>
>>kj wrote:
>>> Is there a way to tell Emacs that, from now on, it should save all
>>> changes to this buffer to the new path (and preferably without
>>> asking for any additional confirmation)?
>
>>you can use C-x C-w to save a buffer to another file. that doesn't delete
>>the original file, but using C-x C-w and then deleting the original file
>>should cause less vexation than your current scenario. ;-)
>
>
> No, that doesn't address the problem I tried (but clearly failed)
> to describe.  I want to prevent cases in which I *inadvertently*
> do C-x C-s, forgetting/not realizing that the current value of
> buffer-file-name is a non-existent path.

Sorry, you did describe it well, I didn't explain very well what I
meant. What I suggested was to change your habit of renaming files from
within the shell to renaming them with C-x C-w in Emacs.

But the before-save-hook that Raffaele mentioned is definitely better... 

--

-- 
Joost Kremers                                      joostkremers <at> yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

(Continue reading)


Gmane