unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#65928: [PATCH] Introduce 'project-save-buffers'
@ 2023-09-13 21:26 me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-14  6:51 ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-13 21:26 UTC (permalink / raw)
  To: 65928

[-- Attachment #1: Type: text/plain, Size: 183 bytes --]

Hi all,

A small patch to introduce a function from projectile that I feel is 
missing, please feel free to yell at me if this has already been 
rejected :)

Thanks all,

Ellis (@lkn)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Introduce-project-save-buffers.patch --]
[-- Type: text/x-diff; name=0001-Introduce-project-save-buffers.patch, Size: 2103 bytes --]

From baa257a9c60cb629b1ff60a5965530863e9c11e3 Mon Sep 17 00:00:00 2001
From: Ellis Kenyo <me@elken.dev>
Date: Wed, 13 Sep 2023 22:19:54 +0100
Subject: [PATCH] Introduce 'project-save-buffers'

* etc/NEWS: Update NEWS file.

* lisp/progmodes/project.el (project-save-buffers): Add new function to
save all modified buffers in current project.
---
 etc/NEWS                  |  4 ++++
 lisp/progmodes/project.el | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index c146f464585..d9d5f7ffd94 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -828,6 +828,10 @@ additionally traverse the parent directories until a VCS root is found
 (if any), so that the ignore rules for that repository are used, and
 the file listing's performance is still optimized.
 
+*** New command 'project-save-buffers'.
+Save all the modified buffers in the current project. If no relevant
+buffers are found, print a message instead.
+
 \f
 * Incompatible Lisp Changes in Emacs 30.1
 
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 2e6ae89a443..45fb33dc77d 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1646,6 +1646,25 @@ defun project-kill-buffers
           ((funcall query-user)
            (mapc #'kill-buffer bufs)))))
 
+;;;###autoload
+(defun project-save-buffers ()
+  "Save the modified buffers in the current project.
+Two buffers belong to the same project if their
+project instances, as reported by `project-current' in each
+buffer, are identical. "
+  (interactive)
+  (let* ((pr (project-current t))
+         (bufs (cl-remove-if-not (lambda (buf)
+                                   (and (buffer-file-name buf)
+                                        (buffer-modified-p buf)))
+                                 (project-buffers pr))))
+    (if (null bufs)
+        (message "No buffers to save in %s" (project-name pr))
+      (dolist (buf bufs)
+        (with-current-buffer buf
+          (save-buffer)))
+      (message "Saved %d buffers in %s" (length bufs) (project-name pr)))))
+
 \f
 ;;; Project list
 
-- 
2.41.0


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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-13 21:26 bug#65928: [PATCH] Introduce 'project-save-buffers' me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-14  6:51 ` Juri Linkov
  2023-09-14 13:45   ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-14 14:07   ` Stefan Kangas
  0 siblings, 2 replies; 13+ messages in thread
From: Juri Linkov @ 2023-09-14  6:51 UTC (permalink / raw)
  To: me; +Cc: 65928

> A small patch to introduce a function from projectile that I feel is
> missing, please feel free to yell at me if this has already been rejected
> :)

Thanks for the patch.  However, this is already implemented in
'save-some-buffers-root'.  OTOH, having a separate command
maybe be not so bad.  It could be bound to 'C-x p C-x s'.





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14  6:51 ` Juri Linkov
@ 2023-09-14 13:45   ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-14 14:09     ` Stefan Kangas
  2023-09-14 14:30     ` Dmitry Gutov
  2023-09-14 14:07   ` Stefan Kangas
  1 sibling, 2 replies; 13+ messages in thread
From: Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-14 13:45 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 65928

[-- Attachment #1: Type: text/plain, Size: 529 bytes --]

Implemented somewhat yeah, but I think it's sensible and more discoverable having one here as you say. :)

On 14 September 2023 07:51:02 BST, Juri Linkov <juri@linkov.net> wrote:
>> A small patch to introduce a function from projectile that I feel is
>> missing, please feel free to yell at me if this has already been rejected
>> :)
>
>Thanks for the patch.  However, this is already implemented in
>'save-some-buffers-root'.  OTOH, having a separate command
>maybe be not so bad.  It could be bound to 'C-x p C-x s'.

[-- Attachment #2: Type: text/html, Size: 997 bytes --]

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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14  6:51 ` Juri Linkov
  2023-09-14 13:45   ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-14 14:07   ` Stefan Kangas
  2023-09-14 14:13     ` Dmitry Gutov
                       ` (2 more replies)
  1 sibling, 3 replies; 13+ messages in thread
From: Stefan Kangas @ 2023-09-14 14:07 UTC (permalink / raw)
  To: Juri Linkov, me; +Cc: 65928

Juri Linkov <juri@linkov.net> writes:

> It could be bound to 'C-x p C-x s'.

What's the binding in projectile?  All else being equal, I'd suggest we
use the same one.





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14 13:45   ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-14 14:09     ` Stefan Kangas
  2023-09-14 14:12       ` Dmitry Gutov
  2023-09-14 14:18       ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-14 14:30     ` Dmitry Gutov
  1 sibling, 2 replies; 13+ messages in thread
From: Stefan Kangas @ 2023-09-14 14:09 UTC (permalink / raw)
  To: Elken, Juri Linkov; +Cc: 65928

Elken via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs@gnu.org> writes:

> Implemented somewhat yeah, but I think it's sensible and more
> discoverable having one here as you say. :)

Would something like

    (defalias 'project-save-buffers #'save-some-buffers-root)

do the job?





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14 14:09     ` Stefan Kangas
@ 2023-09-14 14:12       ` Dmitry Gutov
  2023-09-14 14:18       ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-09-14 14:12 UTC (permalink / raw)
  To: Stefan Kangas, Elken, Juri Linkov; +Cc: 65928

On 14/09/2023 17:09, Stefan Kangas wrote:
> Elken via "Bug reports for GNU Emacs, the Swiss army knife of text
> editors"<bug-gnu-emacs@gnu.org>  writes:
> 
>> Implemented somewhat yeah, but I think it's sensible and more
>> discoverable having one here as you say. 😄
> Would something like
> 
>      (defalias 'project-save-buffers #'save-some-buffers-root)
> 
> do the job?

save-some-buffers-root is not a command, just a predicate function.





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14 14:07   ` Stefan Kangas
@ 2023-09-14 14:13     ` Dmitry Gutov
  2023-09-14 14:16     ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-15  6:32     ` Juri Linkov
  2 siblings, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-09-14 14:13 UTC (permalink / raw)
  To: Stefan Kangas, Juri Linkov, me; +Cc: 65928

On 14/09/2023 17:07, Stefan Kangas wrote:
> Juri Linkov<juri@linkov.net>  writes:
> 
>> It could be bound to 'C-x p C-x s'.
> What's the binding in projectile?  All else being equal, I'd suggest we
> use the same one.

The counterpart to Projectile's binding will be 'C-x p S'.

But in its keymap lowercase 's' is a prefix binding with several 
subcommands (grep, ripgrep, ag, references). Maybe that's not important.





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14 14:07   ` Stefan Kangas
  2023-09-14 14:13     ` Dmitry Gutov
@ 2023-09-14 14:16     ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-15  6:32     ` Juri Linkov
  2 siblings, 0 replies; 13+ messages in thread
From: me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-14 14:16 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 65928, Juri Linkov

On 2023-09-14 15:07, Stefan Kangas wrote:
> Juri Linkov <juri@linkov.net> writes:
> 
>> It could be bound to 'C-x p C-x s'.
> 
> What's the binding in projectile?  All else being equal, I'd suggest we
> use the same one.

"S" in the `projectile-command-map'





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14 14:09     ` Stefan Kangas
  2023-09-14 14:12       ` Dmitry Gutov
@ 2023-09-14 14:18       ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 13+ messages in thread
From: me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-14 14:18 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 65928, Juri Linkov

On 2023-09-14 15:09, Stefan Kangas wrote:
> Elken via "Bug reports for GNU Emacs, the Swiss army knife of text
> editors" <bug-gnu-emacs@gnu.org> writes:
> 
>> Implemented somewhat yeah, but I think it's sensible and more
>> discoverable having one here as you say. :)
> 
> Would something like
> 
>     (defalias 'project-save-buffers #'save-some-buffers-root)
> 
> do the job?

It's a predicate to pass to `save-some-buffers`, so you'd still need an 
interactive command to call it and handle the universal argument





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14 13:45   ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-14 14:09     ` Stefan Kangas
@ 2023-09-14 14:30     ` Dmitry Gutov
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-09-14 14:30 UTC (permalink / raw)
  To: Elken, Juri Linkov; +Cc: 65928

On 14/09/2023 16:45, Elken via Bug reports for GNU Emacs, the Swiss army 
knife of text editors wrote:
> Implemented somewhat yeah, but I think it's sensible and more 
> discoverable having one here as you say. :)

I suppose the main question is whether we want a 
project-save-some-buffers (one that can iterate through unsaved buffers 
but can also save them all with an extra keypress) or a straight copy of 
Projectile's command that just saves all buffers.

I don't use the iteration ability often, but once in a blue moon it does 
come in handy. Though perhaps one can continue using save-some-buffer 
for that (with the default predicate or not).





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-14 14:07   ` Stefan Kangas
  2023-09-14 14:13     ` Dmitry Gutov
  2023-09-14 14:16     ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-15  6:32     ` Juri Linkov
  2023-09-15 16:39       ` Dmitry Gutov
  2 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-09-15  6:32 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 65928, me

>> It could be bound to 'C-x p C-x s'.

After more thoughts, it's not the best keybinding:
the global 'C-x s' could be used to save all buffers
in another project with 'C-x p p ... C-x s'
implemented in bug#63648.

> What's the binding in projectile?  All else being equal, I'd suggest we
> use the same one.

Maybe Projectile's binding 'C-x p S' is not too bad.

> Would something like
>     (defalias 'project-save-buffers #'save-some-buffers-root)
> do the job?

Rather something more like this will do the job:

```
(keymap-set project-prefix-map "S"
            (lambda (&optional arg)
              (interactive "P")
              (let ((save-some-buffers-default-predicate 'save-some-buffers-root))
                (save-some-buffers arg))))
```





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-15  6:32     ` Juri Linkov
@ 2023-09-15 16:39       ` Dmitry Gutov
  2023-09-18  6:56         ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-09-15 16:39 UTC (permalink / raw)
  To: Juri Linkov, Stefan Kangas; +Cc: 65928, me

On 15/09/2023 09:32, Juri Linkov wrote:
>> Would something like
>>      (defalias 'project-save-buffers #'save-some-buffers-root)
>> do the job?
> Rather something more like this will do the job:
> 
> ```
> (keymap-set project-prefix-map "S"
>              (lambda (&optional arg)
>                (interactive "P")
>                (let ((save-some-buffers-default-predicate 'save-some-buffers-root))
>                  (save-some-buffers arg))))
> ```

Would you say that the added capability to only save certain buffers but 
not others, is something you found useful in practice?

More than once a year or so.





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

* bug#65928: [PATCH] Introduce 'project-save-buffers'
  2023-09-15 16:39       ` Dmitry Gutov
@ 2023-09-18  6:56         ` Juri Linkov
  0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2023-09-18  6:56 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Stefan Kangas, me, 65928

>>> Would something like
>>>      (defalias 'project-save-buffers #'save-some-buffers-root)
>>> do the job?
>> Rather something more like this will do the job:
>> ```
>> (keymap-set project-prefix-map "S"
>>              (lambda (&optional arg)
>>                (interactive "P")
>>                (let ((save-some-buffers-default-predicate 'save-some-buffers-root))
>>                  (save-some-buffers arg))))
>> ```
>
> Would you say that the added capability to only save certain buffers but
> not others, is something you found useful in practice?
>
> More than once a year or so.

I don't know why might anyone want to save only project's buffer,
but not all.  I use 'C-x s' only when 'C-c C-a' from diff-mode modifies
different buffers (hopefully a new diff command will save them at once),
but I don't mind when 'C-x s' saves non-project buffers as well.





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

end of thread, other threads:[~2023-09-18  6:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-13 21:26 bug#65928: [PATCH] Introduce 'project-save-buffers' me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-14  6:51 ` Juri Linkov
2023-09-14 13:45   ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-14 14:09     ` Stefan Kangas
2023-09-14 14:12       ` Dmitry Gutov
2023-09-14 14:18       ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-14 14:30     ` Dmitry Gutov
2023-09-14 14:07   ` Stefan Kangas
2023-09-14 14:13     ` Dmitry Gutov
2023-09-14 14:16     ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15  6:32     ` Juri Linkov
2023-09-15 16:39       ` Dmitry Gutov
2023-09-18  6:56         ` Juri Linkov

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