* Tweaking save-some-buffers-action-alist @ 2021-06-17 16:12 Sergey Organov 2021-06-17 21:55 ` Daniel Martín 0 siblings, 1 reply; 5+ messages in thread From: Sergey Organov @ 2021-06-17 16:12 UTC (permalink / raw To: emacs-devel Hello, In this discussion: https://lists.gnu.org/archive/html/help-gnu-emacs/2021-06/msg00165.html I was pointed by Eli to `some-some-buffers-action-alist` as possible way to get the feature I've asked for (revert buffer from `same-some-buffers` prompt). I believe that this capability is really missing when `enable-recursive-minibuffers` is nil, that is now the default. This doesn't seem to have direct support for user-level customization, so I came-up with the following tweak to my init.el that "works" for me, but I'm not sure I actually do it right, so please help me with this: #+BEGIN_SRC emacs-lisp (nconc save-some-buffers-action-alist '((?\C-\M-g (lambda (buf) (with-current-buffer buf (revert-buffer))) "revert this buffer"))) #+END_SRC I'm concerned as I use `nconc` that sounds unsafe, and then original definition has some ",(" and ",(purecopy" tricks that I dunno if I need to follow, and if so, how? And to finally justify posting to 'emacs-devel', does it make sense to add this capability to the default value of `save-some-buffers-action-alist`? To give you some more context for thoughts, not only I'm often get annoyed myself by the absence of the feature, but I recently got this question: "how do I discard changes to the buffer when I run `compile` and Emacs asks me if I want to save some?" from a relatively novice Emacs user I'm trying to help, and I really hate to answer: "no way." Thanks, -- Sergey Organov ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tweaking save-some-buffers-action-alist 2021-06-17 16:12 Tweaking save-some-buffers-action-alist Sergey Organov @ 2021-06-17 21:55 ` Daniel Martín 2021-06-18 19:16 ` Sergey Organov 0 siblings, 1 reply; 5+ messages in thread From: Daniel Martín @ 2021-06-17 21:55 UTC (permalink / raw To: Sergey Organov; +Cc: emacs-devel Sergey Organov <sorganov@gmail.com> writes: > > #+BEGIN_SRC emacs-lisp > (nconc > save-some-buffers-action-alist > '((?\C-\M-g > (lambda (buf) > (with-current-buffer buf > (revert-buffer))) > "revert this buffer"))) > #+END_SRC > > I'm concerned as I use `nconc` that sounds unsafe, and then original > definition has some ",(" and ",(purecopy" tricks that I dunno if I need > to follow, and if so, how? Purecopy is a no-op except while Emacs is being built and dumped, so user customizations can omit it. Evaluate (info "(elisp) Pure Storage") in Emacs to read more about this. Backquoting the alist will instruct the Elisp interpreter to not evaluate KEY, but evaluate the lambda FUNC. Evaluating lambda expressions is generally a good idea because that enables byte-compilation and all its benefits: Faster code, less memory usage, some static checks, specially under lexical scope, etc. > > And to finally justify posting to 'emacs-devel', does it make sense to > add this capability to the default value of > `save-some-buffers-action-alist`? > I think reverting a buffer when compiling is not a very common need. More importantly, the prompt already has a lot of options and adding one more will make it more complex and difficult to understand. At some point you have to draw the line between what should be a customization and what should be included in Emacs and I think your suggestion can perfectly be a personal customization. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tweaking save-some-buffers-action-alist 2021-06-17 21:55 ` Daniel Martín @ 2021-06-18 19:16 ` Sergey Organov 2021-06-18 23:02 ` Stefan Monnier 0 siblings, 1 reply; 5+ messages in thread From: Sergey Organov @ 2021-06-18 19:16 UTC (permalink / raw To: Daniel Martín; +Cc: emacs-devel Daniel Martín <mardani29@yahoo.es> writes: > Sergey Organov <sorganov@gmail.com> writes: > >> >> #+BEGIN_SRC emacs-lisp >> (nconc >> save-some-buffers-action-alist >> '((?\C-\M-g >> (lambda (buf) >> (with-current-buffer buf >> (revert-buffer))) >> "revert this buffer"))) >> #+END_SRC >> >> I'm concerned as I use `nconc` that sounds unsafe, and then original >> definition has some ",(" and ",(purecopy" tricks that I dunno if I need >> to follow, and if so, how? > > Purecopy is a no-op except while Emacs is being built and dumped, so > user customizations can omit it. Evaluate (info "(elisp) Pure Storage") > in Emacs to read more about this. > > Backquoting the alist will instruct the Elisp interpreter to not > evaluate KEY, but evaluate the lambda FUNC. Evaluating lambda > expressions is generally a good idea because that enables > byte-compilation and all its benefits: Faster code, less memory usage, > some static checks, specially under lexical scope, etc. Thanks for clarification and pointers! Is `nconc` safe here, or should I `copy-seq` the original and modify that instead? > >> >> And to finally justify posting to 'emacs-devel', does it make sense to >> add this capability to the default value of >> `save-some-buffers-action-alist`? >> > > I think reverting a buffer when compiling is not a very common need. Surprisingly, it /is/ rather common when one has a lot of (often unrelated to compilation) buffers, and finding the buffer in question after compilation just to revert it is boring and is often forgotten until the next compilation. Annoying. > More importantly, the prompt already has a lot of options and adding one > more will make it more complex and difficult to understand. Well, yes, but I believe that the "Discard changes" option is the second or third by usefulness among the rest supported: "Save Changes, Discard Changes, Save All". To me it's "Ignore the change and continue" that seems to be the least useful one. I just want to have a way to finish entire prompt series and have no modified buffers at the end. Doesn't seem to be too much to ask for. As a side note, if there are too many options already, 'C-r' could be removed and the buffer in question be shown automatically instead. > At some point you have to draw the line between what should be a > customization and what should be included in Emacs Yep. I just think that the line in this particular case has been chosen long ago, when `enable-recursive-minibuffers` was enabled by default, or was unheard of, and now, when it is disabled by default, the line should be drawn at a different level, making it possible again to conveniently revert the buffer. > and I think your suggestion can perfectly be a personal customization. Probably it could, but right now it isn't. I don't think we can expect a novice user to be able to tweak it like I did above, no way. Do you in fact suggest to support this through `customize` or what? The current state is that to the actual question I got from a novice user: "How do I discard changes to the buffer when I run `compile` and Emacs asks me if I want to save some?" I have to either give the "No way" answer, or tweak Emacs for them. Sad. BTW, if there were a way to cancel the `save-some-buffers` after 'C-r' yet leave the modified buffer current, it'd solve the issue as well, though in a different, less convenient way. Thanks, -- Sergey Organov ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tweaking save-some-buffers-action-alist 2021-06-18 19:16 ` Sergey Organov @ 2021-06-18 23:02 ` Stefan Monnier 2021-06-19 12:31 ` Sergey Organov 0 siblings, 1 reply; 5+ messages in thread From: Stefan Monnier @ 2021-06-18 23:02 UTC (permalink / raw To: Sergey Organov; +Cc: Daniel Martín, emacs-devel > Is `nconc` safe here, or should I `copy-seq` the original and modify > that instead? The general rule is: If you don't know, then it's not safe. [ and indeed, it's not safe in this particular case. ] Stefan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tweaking save-some-buffers-action-alist 2021-06-18 23:02 ` Stefan Monnier @ 2021-06-19 12:31 ` Sergey Organov 0 siblings, 0 replies; 5+ messages in thread From: Sergey Organov @ 2021-06-19 12:31 UTC (permalink / raw To: Stefan Monnier; +Cc: emacs-devel, Daniel Martín Stefan Monnier <monnier@iro.umontreal.ca> writes: >> Is `nconc` safe here, or should I `copy-seq` the original and modify >> that instead? > > The general rule is: If you don't know, then it's not safe. > [ and indeed, it's not safe in this particular case. ] Nice, thanks for confirming! So I ended-up adding new item at the beginning of the list rather than at the end: #+BEGIN_SRC emacs-lisp (push '(?R (lambda (buf) (with-current-buffer buf (revert-buffer))) "revert this buffer") save-some-buffers-action-alist) #+END_SRC And then I had to change the KEY from C-M-g to just R, as on terminal it seems to be impossible to generate the former key-sequence from `map-y-or-n-p`, as "ESC C-g" doesn't work as expected (ESC is simply ignored), – yet another surprising limitation of the mode. Thanks, -- Sergey Organov ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-06-19 12:31 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-06-17 16:12 Tweaking save-some-buffers-action-alist Sergey Organov 2021-06-17 21:55 ` Daniel Martín 2021-06-18 19:16 ` Sergey Organov 2021-06-18 23:02 ` Stefan Monnier 2021-06-19 12:31 ` Sergey Organov
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git 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).