unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to revert buffer from "Save file?" prompt?
@ 2021-06-07 14:24 Sergey Organov
  2021-06-07 14:28 ` Eli Zaretskii
  2021-06-07 15:23 ` Óscar Fuentes
  0 siblings, 2 replies; 10+ messages in thread
From: Sergey Organov @ 2021-06-07 14:24 UTC (permalink / raw)
  To: help-gnu-emacs

Hello!

When I have a modified buffer and run, say "compile", emacs asks to:

Save file /home/osv/f/firm/make/defaults.make? (y, n, !, ., q, C-r, d or C-h)

and the set of choices doesn't seem to include "discard changes", or
"revert buffer" in emacs terminology.

What is the most convenient way to revert this particular buffer once
I'm there at this prompt?

Thanks,
-- Sergey Organov.



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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-07 14:24 How to revert buffer from "Save file?" prompt? Sergey Organov
@ 2021-06-07 14:28 ` Eli Zaretskii
  2021-06-08 15:18   ` Sergey Organov
  2021-06-07 15:23 ` Óscar Fuentes
  1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2021-06-07 14:28 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Sergey Organov <sorganov@gmail.com>
> Date: Mon, 07 Jun 2021 17:24:14 +0300
> 
> When I have a modified buffer and run, say "compile", emacs asks to:
> 
> Save file /home/osv/f/firm/make/defaults.make? (y, n, !, ., q, C-r, d or C-h)
> 
> and the set of choices doesn't seem to include "discard changes", or
> "revert buffer" in emacs terminology.
> 
> What is the most convenient way to revert this particular buffer once
> I'm there at this prompt?

Why do you need to revert?  If you answer 'n' (= NO), the compilation
will use the version on disk, without saving your edits.  You can
later revert the buffer, but that's a separate operation.

IOW, if all you want is to revert the buffer _without_ compiling, just
type C-g to abort "M-x compile" and then revert.



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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-07 14:24 How to revert buffer from "Save file?" prompt? Sergey Organov
  2021-06-07 14:28 ` Eli Zaretskii
@ 2021-06-07 15:23 ` Óscar Fuentes
  2021-06-07 15:42   ` Sergey Organov
  1 sibling, 1 reply; 10+ messages in thread
From: Óscar Fuentes @ 2021-06-07 15:23 UTC (permalink / raw)
  To: help-gnu-emacs

Sergey Organov <sorganov@gmail.com> writes:

> When I have a modified buffer and run, say "compile", emacs asks to:
>
> Save file /home/osv/f/firm/make/defaults.make? (y, n, !, ., q, C-r, d or C-h)
>
> and the set of choices doesn't seem to include "discard changes", or
> "revert buffer" in emacs terminology.
>
> What is the most convenient way to revert this particular buffer once
> I'm there at this prompt?

What you ask for seems quite dangerous. Better to not make it
convenient.

Right now you need to cancel the `compile' command at the prompt with
C-g, switch to the buffer and revert it with `revert-buffer'.




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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-07 15:23 ` Óscar Fuentes
@ 2021-06-07 15:42   ` Sergey Organov
  0 siblings, 0 replies; 10+ messages in thread
From: Sergey Organov @ 2021-06-07 15:42 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: help-gnu-emacs

Óscar Fuentes <ofv@wanadoo.es> writes:

> Sergey Organov <sorganov@gmail.com> writes:
>
>> When I have a modified buffer and run, say "compile", emacs asks to:
>>
>> Save file /home/osv/f/firm/make/defaults.make? (y, n, !, ., q, C-r, d or C-h)
>>
>> and the set of choices doesn't seem to include "discard changes", or
>> "revert buffer" in emacs terminology.
>>
>> What is the most convenient way to revert this particular buffer once
>> I'm there at this prompt?
>
> What you ask for seems quite dangerous. Better to not make it
> convenient.

Well, I'm willing to take the risk. I can already see diff with 'd', see
the buffer with 'C-r', so I have all the tools to make sure I mean to
discard the changes, and then Emacs will still ask me:

Revert buffer from file /home/osv/f/firm/make/defaults.make? (y or n)

right?

In the end, doesn't seem to be that dangerous to me.

Is there a way to add features to this prompt through customizations?
I'd then opt for C-M-g: revert the buffer.

>
> Right now you need to cancel the `compile' command at the prompt with
> C-g, switch to the buffer and revert it with `revert-buffer'.

Thanks, this way I do know, but often it's very inconvenient, especially
when there are multiple buffers to handle.

-- Sergey Organov




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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-07 14:28 ` Eli Zaretskii
@ 2021-06-08 15:18   ` Sergey Organov
  2021-06-08 15:41     ` Eli Zaretskii
  2021-06-08 15:51     ` Stefan Möding
  0 siblings, 2 replies; 10+ messages in thread
From: Sergey Organov @ 2021-06-08 15:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Sergey Organov <sorganov@gmail.com>
>> Date: Mon, 07 Jun 2021 17:24:14 +0300
>> 
>> When I have a modified buffer and run, say "compile", emacs asks to:
>> 
>> Save file /home/osv/f/firm/make/defaults.make? (y, n, !, ., q, C-r, d or C-h)
>> 
>> and the set of choices doesn't seem to include "discard changes", or
>> "revert buffer" in emacs terminology.
>> 
>> What is the most convenient way to revert this particular buffer once
>> I'm there at this prompt?
>
> Why do you need to revert?  If you answer 'n' (= NO), the compilation
> will use the version on disk, without saving your edits.  You can
> later revert the buffer, but that's a separate operation.

Yes, and that's exactly the problem. It will ask me again and again
every time I compile. Annoying as hell.

>
> IOW, if all you want is to revert the buffer _without_ compiling, just
> type C-g to abort "M-x compile" and then revert.

No, I want to compile, and I don't need the changes in some buffer(s)
anymore. With current design I need to remember the buffer(s), maybe
answer a few more questions until compilation is finally being run,
switch to every buffer I rarely still remembered in turn, and revert
it(them). The latter activity is also often superseded by compilation
errors that get my attention and I forget about the changed buffer(s).
Make fixes to the code, save, run compile and... boom! The prompt is
back. Isn't that *a lot* of trouble that'd be solved by a simple option
for discarding changes?

Probably something like revert-some-buffers (similar to
save-some-buffer) would help as well, but a feature to discard changes
from the "save file" prompt would be definitely more helpful.

As I've asked in another mail: is there a practical way to add
keybindings to this prompt? I'd then opt for adding "C-M-g: revert the
buffer" and be finally done with it.

Also, while we are at this, emacs is extremely modal when at this
prompt, not allowing me to switch to the buffer (to revert it) even when
I view it using 'C-r'. This feels rather unnatural and too limiting for
otherwise very non-modal design.

Thanks,
-- Sergey Organov



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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-08 15:18   ` Sergey Organov
@ 2021-06-08 15:41     ` Eli Zaretskii
  2021-06-08 17:15       ` Sergey Organov
  2021-06-10 17:14       ` Sergey Organov
  2021-06-08 15:51     ` Stefan Möding
  1 sibling, 2 replies; 10+ messages in thread
From: Eli Zaretskii @ 2021-06-08 15:41 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Sergey Organov <sorganov@gmail.com>
> Cc: help-gnu-emacs@gnu.org
> Date: Tue, 08 Jun 2021 18:18:46 +0300
> 
> > Why do you need to revert?  If you answer 'n' (= NO), the compilation
> > will use the version on disk, without saving your edits.  You can
> > later revert the buffer, but that's a separate operation.
> 
> Yes, and that's exactly the problem. It will ask me again and again
> every time I compile. Annoying as hell.

Do you want to compile the file, or do you want to revert it?  These
are two orthogonal things, so it sounds strange to me that you seem to
use "M-x compile" as the means to find all the changes buffers and
revert them.

> > IOW, if all you want is to revert the buffer _without_ compiling, just
> > type C-g to abort "M-x compile" and then revert.
> 
> No, I want to compile, and I don't need the changes in some buffer(s)
> anymore.

Then how come you left those buffers modified?  And what does that
have to do with compilation?

> Probably something like revert-some-buffers (similar to
> save-some-buffer) would help as well, but a feature to discard changes
> from the "save file" prompt would be definitely more helpful.

Then this isn't about "M-x compile", right?  It's about being able to
revert some of the modified buffers, either as a separate command, or
as part of "C-x s".  Right?

> As I've asked in another mail: is there a practical way to add
> keybindings to this prompt? I'd then opt for adding "C-M-g: revert the
> buffer" and be finally done with it.

See save-some-buffers-action-alist.

> Also, while we are at this, emacs is extremely modal when at this
> prompt, not allowing me to switch to the buffer (to revert it) even when
> I view it using 'C-r'. This feels rather unnatural and too limiting for
> otherwise very non-modal design.

Some commands are modal for a reason.  Whether this is one of them,
I'm not sure; file a feature-request bug report to see what the Emacs
developers think about that.



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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-08 15:18   ` Sergey Organov
  2021-06-08 15:41     ` Eli Zaretskii
@ 2021-06-08 15:51     ` Stefan Möding
  2021-06-08 17:56       ` Sergey Organov
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Möding @ 2021-06-08 15:51 UTC (permalink / raw)
  To: help-gnu-emacs

Sergey Organov <sorganov@gmail.com> writes:

> Yes, and that's exactly the problem. It will ask me again and again
> every time I compile. Annoying as hell.

Is the problem about trying to compile a file visited in one buffer and
being asked about changed files in some other buffers?

Maybe setting the variable `compilation-ask-about-save' to nil will help
to stop `compile' from asking every time.

-- 
Stefan



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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-08 15:41     ` Eli Zaretskii
@ 2021-06-08 17:15       ` Sergey Organov
  2021-06-10 17:14       ` Sergey Organov
  1 sibling, 0 replies; 10+ messages in thread
From: Sergey Organov @ 2021-06-08 17:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Sergey Organov <sorganov@gmail.com>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Tue, 08 Jun 2021 18:18:46 +0300
>> 
>> > Why do you need to revert?  If you answer 'n' (= NO), the compilation
>> > will use the version on disk, without saving your edits.  You can
>> > later revert the buffer, but that's a separate operation.
>> 
>> Yes, and that's exactly the problem. It will ask me again and again
>> every time I compile. Annoying as hell.
>
> Do you want to compile the file, or do you want to revert it?

I want to compile, and that obviously involves some files. The buffer in
question could be entirely unrelated to the compilation, or it could be
related, it doesn't matter for the issue at hand.

> These are two orthogonal things, so it sounds strange to me that you
> seem to use "M-x compile" as the means to find all the changes buffers
> and revert them.

It's not the means to find such buffers, it's just that I often notice
such buffers when compiling or switching desktops, or leaving emacs. But
on exit there is at least final "exit anyway" option that discards
changes.

>
>> > IOW, if all you want is to revert the buffer _without_ compiling, just
>> > type C-g to abort "M-x compile" and then revert.
>> 
>> No, I want to compile, and I don't need the changes in some buffer(s)
>> anymore.
>
> Then how come you left those buffers modified?  And what does that
> have to do with compilation?

I left those buffers modified, sorry, my mistake. Maybe I thought I'll
need the modification, and now I see I don't anymore.

Now otherwise unrelated compilation annoyingly asks me every time if I
want to save these buffers. No, I don't!

>
>> Probably something like revert-some-buffers (similar to
>> save-some-buffer) would help as well, but a feature to discard changes
>> from the "save file" prompt would be definitely more helpful.
>
> Then this isn't about "M-x compile", right?  It's about being able to
> revert some of the modified buffers, either as a separate command, or
> as part of "C-x s".  Right?

Right, "M-x compile" is just an example where the lack of feature gets
most annoying. As for "C-x s", it could run the would-be function with
the "revert" feature disabled, if it makes more sense.

>
>> As I've asked in another mail: is there a practical way to add
>> keybindings to this prompt? I'd then opt for adding "C-M-g: revert the
>> buffer" and be finally done with it.
>
> See save-some-buffers-action-alist.

Will check, thanks!

-- Sergey Organov




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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-08 15:51     ` Stefan Möding
@ 2021-06-08 17:56       ` Sergey Organov
  0 siblings, 0 replies; 10+ messages in thread
From: Sergey Organov @ 2021-06-08 17:56 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Möding <s.moeding@gmail.com> writes:

> Sergey Organov <sorganov@gmail.com> writes:
>
>> Yes, and that's exactly the problem. It will ask me again and again
>> every time I compile. Annoying as hell.
>
> Is the problem about trying to compile a file visited in one buffer and
> being asked about changed files in some other buffers?

Not exactly, compile is just an indicator of a usability problem, and it
asks about changes in some (other) buffers, yes.

>
> Maybe setting the variable `compilation-ask-about-save' to nil will help
> to stop `compile' from asking every time.

No, this is not an option, I do want to be asked about unsaved changes,
I just want not only to be able to save them, but discard them as well.

Thanks,
-- Sergey Organov



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

* Re: How to revert buffer from "Save file?" prompt?
  2021-06-08 15:41     ` Eli Zaretskii
  2021-06-08 17:15       ` Sergey Organov
@ 2021-06-10 17:14       ` Sergey Organov
  1 sibling, 0 replies; 10+ messages in thread
From: Sergey Organov @ 2021-06-10 17:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Sergey Organov <sorganov@gmail.com>

[...]

>> As I've asked in another mail: is there a practical way to add
>> keybindings to this prompt? I'd then opt for adding "C-M-g: revert the
>> buffer" and be finally done with it.
>
> See save-some-buffers-action-alist.

Here is customization I came up with:

(nconc
 save-some-buffers-action-alist
 '((?\C-\M-g
    (lambda (buf)
      (with-current-buffer buf
        (revert-buffer)))
    "revert this buffer")))

Seems to work as expected. Does it look correct?

What about all the ,( tricks in the original (that didn't work for me)?
Should I somehow adopt them? See:

(defvar save-some-buffers-action-alist
  `((?\C-r
     ,(lambda (buf)
        (if (not enable-recursive-minibuffers)
            (progn (display-buffer buf)
                   (setq other-window-scroll-buffer buf))
          (view-buffer buf (lambda (_) (exit-recursive-edit)))
          (recursive-edit))
        ;; Return nil to ask about BUF again.
        nil)
     ,(purecopy "view this buffer"))))

Thanks,
-- Sergey Organov



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

end of thread, other threads:[~2021-06-10 17:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-07 14:24 How to revert buffer from "Save file?" prompt? Sergey Organov
2021-06-07 14:28 ` Eli Zaretskii
2021-06-08 15:18   ` Sergey Organov
2021-06-08 15:41     ` Eli Zaretskii
2021-06-08 17:15       ` Sergey Organov
2021-06-10 17:14       ` Sergey Organov
2021-06-08 15:51     ` Stefan Möding
2021-06-08 17:56       ` Sergey Organov
2021-06-07 15:23 ` Óscar Fuentes
2021-06-07 15:42   ` Sergey Organov

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).