diff --git a/README.md b/README.md index 9fd9dc27..90f2db1e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/test/rustic-compile-test.el b/test/rustic-compile-test.el index 9b74da29..7fc2447f 100644 --- a/test/rustic-compile-test.el +++ b/test/rustic-compile-test.el @@ -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))) diff --git a/test/test-helper.el b/test/test-helper.el index 830c504d..6f2495fd 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -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) @@ -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)