Skip to content

Commit

Permalink
document how to use buffer-save-without-query
Browse files Browse the repository at this point in the history
and activate it for tests

close #270
  • Loading branch information
brotzeit committed Jan 6, 2022
1 parent d2bd5f7 commit afe8734
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,21 @@ You can format your code with:
- `rustic-format-dwim` run format on region,file or cargo fmt

Rustic uses the function `rustic-save-some-buffers` for saving buffers
before compilation. To save buffers automatically, you can change the
value of `buffer-save-without-query`. In case you prefer using lsp for
before compilation. In case you prefer using lsp for
formatting, turn off `rustic-format-on-save` and set
`rustic-lsp-format`to `t`.

To save buffers automatically, you can change the value of
`buffer-save-without-query`:

```elisp
(defun rustic-mode-auto-save-hook ()
"Enable auto-saving in rustic-mode buffers."
(when buffer-file-name
(setq-local buffer-save-without-query t)))
(add-hook 'rustic-mode-hook 'rustic-mode-auto-save-hook)
```

Customization:

- `rustic-rustfmt-bin` path to rustfmt executable
Expand Down
3 changes: 1 addition & 2 deletions test/rustic-compile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
(with-current-buffer buffer2
(write-file file2)
(insert string))
(let ((buffer-save-without-query t))
(rustic-save-some-buffers))
(rustic-save-some-buffers)
(sit-for 1)
(with-current-buffer buffer1
(should (string= (buffer-string) formatted-string)))
Expand Down
7 changes: 6 additions & 1 deletion test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Emacs shutdown.")
(dir (rustic-babel-generate-project t))
(src (concat dir "/src"))
(file (expand-file-name "main.rs" src))
(buffer-save-without-query t)
(rustic-format-trigger nil))
(with-current-buffer buffer
(write-file file)
Expand Down Expand Up @@ -105,3 +104,9 @@ list of substrings of `STR' each followed by its face."
(font-lock-ensure)
(font-lock-flush)
(buffer-string)))

(defun rustic-mode-auto-save-hook ()
"Enable auto-saving in rustic-mode buffers."
(when buffer-file-name
(setq-local buffer-save-without-query t)))
(add-hook 'rustic-mode-hook 'rustic-mode-auto-save-hook)

0 comments on commit afe8734

Please sign in to comment.