Skip to content

Commit 2f32e89

Browse files
ed9w2in6CeleritasCelery
authored andcommitted
fix(rustic-babel-build-sentinel): align behaviour with other lang
In an org file, the src block's code should be interpreted, OR the binary compiled from it SHOULD execute with PWD as `default-directory` of the org file. Summary of changes: 1. save the original default-directory then later restores it. 2. supply `--manifest-path` option to `cargo run` to execute the target `Cargo.toml` binary compiled from the src block. For reference: Try to execute a C++, C, js (node), python block. In particular, see implementation of `org-babel-C-execute` or `org-babel-python-evaluate-external-process`. May be we can re-write like them in the future. fixes: brotzeit/rustic#509
1 parent 7e51d36 commit 2f32e89

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

rustic-babel.el

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ execution with rustfmt."
112112
(let ((proc-buffer (process-buffer proc))
113113
(inhibit-read-only t))
114114
(if (zerop (process-exit-status proc))
115-
(let* ((default-directory rustic-babel-dir))
115+
(let* ((original-default-directory default-directory)
116+
(default-directory rustic-babel-dir))
116117

117118
;; format babel block
118119
(when (and rustic-babel-format-src-block (not rustic-babel-auto-wrap-main) (not main-p))
@@ -121,9 +122,21 @@ execution with rustfmt."
121122
(sit-for 0.1))))
122123

123124
;; run project
124-
(let* ((err-buff (get-buffer-create rustic-babel-compilation-buffer-name))
125-
(params (list "cargo" toolchain "run" "--quiet"))
126-
(inhibit-read-only t))
125+
(let* ((err-buff
126+
(get-buffer-create rustic-babel-compilation-buffer-name))
127+
(params
128+
(list
129+
"cargo"
130+
toolchain
131+
"run"
132+
"--manifest-path"
133+
(format "%s/Cargo.toml" rustic-babel-dir)
134+
"--quiet"))
135+
(inhibit-read-only t)
136+
;; command should run in the original default-directory
137+
;; which is typically the original org file
138+
;; This agrees with behaviour of C, C++, D, js, python, etc.
139+
(default-directory original-default-directory))
127140
(rustic-make-process
128141
:name rustic-babel-process-name
129142
:buffer err-buff

0 commit comments

Comments
 (0)