Skip to content

Commit

Permalink
Merge pull request #320 from lroolle/bugfix/cargo-run-example
Browse files Browse the repository at this point in the history
rustic-cargo: fix cargo run --example detect crate root(#319)
  • Loading branch information
brotzeit authored Jan 29, 2022
2 parents 6bda15c + 1a8bc7d commit 3151f3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rustic-babel.el
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ kill the running process."
(let ((default-directory dir)
(toolchain (cdr (assq :toolchain params))))
(write-region
(concat "#![allow(non_snake_case)]\n"
(concat "#![allow(non_snake_case, unused)]\n"
(if use-blocks (rustic-babel-insert-mod use-blocks) "")
(if include-blocks (rustic-babel-include-blocks include-blocks) "")
(if wrap-main (rustic-babel-ensure-main-wrap body) body))
Expand Down
18 changes: 9 additions & 9 deletions rustic-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,15 @@ When calling this function from `rustic-popup-mode', always use the value of

(defun rustic-cargo-run-get-relative-example-name ()
"Run 'cargo run --example' if current buffer within a 'examples' directory."
(if rustic--buffer-workspace
(let ((relative-filenames
(split-string (file-relative-name buffer-file-name rustic--buffer-workspace) "/")))
(if (string= "examples" (car relative-filenames))
(let ((size (length relative-filenames)))
(cond ((eq size 2) (file-name-sans-extension(nth 1 relative-filenames))) ;; examples/single-example1.rs
((> size 2) (car (nthcdr (- size 2) relative-filenames))) ;; examples/example2/main.rs
(t nil))) nil))
nil))
(let* ((buffer-project-root (rustic-buffer-crate))
(relative-filenames
(if buffer-project-root
(split-string (file-relative-name buffer-file-name buffer-project-root) "/") nil)))
(if (and relative-filenames (string= "examples" (car relative-filenames)))
(let ((size (length relative-filenames)))
(cond ((eq size 2) (file-name-sans-extension (nth 1 relative-filenames))) ;; examples/single-example1.rs
((> size 2) (car (nthcdr (- size 2) relative-filenames))) ;; examples/example2/main.rs
(t nil))) nil)))

;;;###autoload
(defun rustic-run-shell-command (&optional arg)
Expand Down

0 comments on commit 3151f3e

Please sign in to comment.