Skip to content

Commit 5e87656

Browse files
committed
Only save the current buffer, by default
1 parent 562597d commit 5e87656

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

README.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,20 @@ Here's the code to do this:
8080
```
8181
- `pathaction-after-create-buffer-hook`: This hook is executed after the pathaction buffer is created. It runs from within the pathaction buffer, enabling further customization or actions once the buffer is available.
8282

83-
## Preventing save-some-buffers from asking the user if they really want to save the current buffer
83+
## Saving all buffers before executing pathaction
8484

85-
By default, `pathaction-before-run-hook` triggers `save-some-buffers` to ensure that all buffers are saved before executing actions or commands that impact the current buffer or any other buffer being edited.
85+
By default, `pathaction-before-run-hook` only calls a function to save the current buffer before executing actions or commands that affect the current or any other edited buffer.
8686

87-
By default, `save-some-buffers` requests user confirmation.
88-
89-
To disable the confirmation prompt from `save-some-buffers`, use the following configuration:
87+
To make `pathaction` save all buffers, use the following configuration:
9088
```emacs-lisp
9189
(defun my-save-some-buffers ()
9290
"Prevent `save-some-buffers' from prompting by passing 1 to it."
93-
(save-some-buffers 1))
94-
95-
;; Remove: `save-some-buffers'
96-
(remove-hook 'pathaction-before-run-hook #'save-some-buffers)
91+
(save-some-buffers))
9792
98-
;; Add: `my-save-some-buffers'
9993
(add-hook 'pathaction-before-run-hook #'my-save-some-buffers)
10094
```
10195

102-
This will disable all interactive prompts when saving buffers using `save-some-buffers`.
103-
104-
**Customizing `save-some-buffers`:** The `save-some-buffers` function can be customized by setting `save-some-buffers-default-predicate` to a predicate function that returns nil for files that should not be automatically saved.
96+
(If you want to prevent `save-some-buffers` from prompting the user before saving, replace `(save-some-buffers)` with `(save-some-buffers t)`.)
10597

10698
## Author and License
10799

pathaction.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ Defaults to `ansi-term'.
5353
of the buffer as the second argument.
5454
Example: (function-name command buffername)")
5555

56-
(defcustom pathaction-before-run-hook '(save-some-buffers)
57-
"Hooks to run before `pathaction-run' executes the `pathaction` command.
58-
By default, it calls `save-some-buffers'."
56+
(defun pathaction--save-buffer ()
57+
"Save the current buffer if it is visiting a file."
58+
(let ((file-name (buffer-file-name (buffer-base-buffer)))
59+
(save-silently t))
60+
(when file-name
61+
(save-buffer))))
62+
63+
(defcustom pathaction-before-run-hook '(pathaction--save-buffer)
64+
"Hooks to run before `pathaction-run' executes the `pathaction` command."
5965
:group 'pathaction
6066
:type 'hook)
6167

0 commit comments

Comments
 (0)