diff --git a/CHANGELOG.org b/CHANGELOG.org index 4988819..eb993c1 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -21,4 +21,6 @@ - ~rustic-recompile~ will remember any universal arguments that is passed to it. - Fix ~rustic-cargo-upgrade~ in the presence of universal arguments. -- Fix ~rusti-cargo-clippy-rerun~ to use the last used arguments. +- Fix ~rustic-cargo-clippy-rerun~ to use the last used arguments. +- Implement ~rustic-babel-display-error-popup~ customization + option. Refer the variable docs for more details. diff --git a/README.md b/README.md index 341c793..e110479 100644 --- a/README.md +++ b/README.md @@ -672,6 +672,9 @@ Customization: of babel process - `rustic-babel-auto-wrap-main` wrap body into main function - `rustic-babel-default-toolchain` active toolchain for babel blocks +- `rustic-babel-display-error-popup` displays error popup on + compilation failure or when the exit code is non zero. Set it to nil + if you want it to be displayed as part of result block. ### lsp-mode diff --git a/rustic-babel.el b/rustic-babel.el index 6ebf955..e190b28 100644 --- a/rustic-babel.el +++ b/rustic-babel.el @@ -22,6 +22,14 @@ :type 'boolean :group 'rustic-babel) +(defcustom rustic-babel-display-error-popup t + "Diplay compilation error or panic in error popup. +On failures and panic during execution, should the error be +displayed separately or as part of popup or should it be part of +results block ? By default we display it as separate popup." + :type 'boolean + :group 'rustic-babel) + (defcustom rustic-babel-auto-wrap-main t "Whether to auto wrap body in `fn main' to function call if none exists." :type 'boolean @@ -158,12 +166,15 @@ execution with rustfmt." (save-excursion (save-match-data (goto-char (point-min)) - (when (re-search-forward "^thread '[^']+' panicked at .*") - (goto-char (match-beginning 0)) - (setq result (buffer-substring-no-properties (point) (line-end-position))))))) + (if rustic-babel-display-error-popup + (when (re-search-forward "^thread '[^']+' panicked at .*") + (goto-char (match-beginning 0)) + (setq result (buffer-substring-no-properties (point) (line-end-position)))) + (setq result (buffer-string)))))) (rustic-babel-run-update-result-block result) (rustic-with-spinner rustic-babel-spinner nil nil) - (pop-to-buffer proc-buffer))))) + (when rustic-babel-display-error-popup + (pop-to-buffer proc-buffer)))))) (defun rustic-babel-build-update-result-block (result) "Update result block with RESULT." diff --git a/test/rustic-babel-test.el b/test/rustic-babel-test.el index 4c03d80..5fade6c 100644 --- a/test/rustic-babel-test.el +++ b/test/rustic-babel-test.el @@ -61,6 +61,16 @@ (should (eq (rustic-test-babel-check-results buf) nil)) (should-not (buffer-live-p rustic-babel-compilation-buffer-name)))) +(ert-deftest rustic-test-babel-error-no-popup () + (let* ((string "fn main() { + panic!(\"hello world\"); + }") + (buf (rustic-test-get-babel-block string)) + (rustic-babel-display-error-popup nil)) + (rustic-test-babel-execute-block buf) + ;; The output will have some message of panic + (should (s-contains? "panic" (rustic-test-babel-check-results buf))))) + (ert-deftest rustic-test-babel-error-results () (let* ((string "fn main() { let v = vec![1, 2, 3];