Skip to content

Commit cbb8a32

Browse files
dcorkinggrafov
authored andcommitted
Update compiler command (#3)
* Update compiler command to `cargo build` to fix linker errors such as ``` rustc /Users/dcorking/.emacs.d/rust-playground/at-2018-03-01-151124/snippet.rs -o snippet && /Users/dcorking/.emacs.d/rust-playground/at-2018-03-01-151124/snippet error: linking with `cc` failed: exit code: 1 = note: "cc" "-m64" ... = note: Undefined symbols for architecture x86_64: "core::num::ptr_try_from_impls::_$LT$impl$u20$core..convert..TryFrom$LT$usize$GT$$u20$for$u20$u32$GT$::try_from::h5e23b89a45adacda", referenced from: _$LT$i32$u20$as$u20$core..iter..range..Step$GT$::add_usize::he621463dabd6b191 in snippet.snippet9.rcgu.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` * Improve layout of current-snippet-file code
1 parent ff41494 commit cbb8a32

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

rust-playground.el

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,20 @@ By default confirmation required."
8080
:keymap '(([C-return] . rust-playground-exec)))
8181

8282
(defun rust-playground-snippet-file-name(&optional snippet-name)
83-
(setq-local rust-playground-current-snippet-file (let ((file-name (cond (snippet-name)
84-
(rust-playground-ask-file-name
85-
(read-string "Rust Playground filename: ")) ("snippet"))))
86-
(concat (rust-playground-snippet-unique-dir file-name) "/" file-name ".rs"))))
83+
(setq-local rust-playground-current-snippet-file
84+
(let ((file-name
85+
(cond (snippet-name)
86+
(rust-playground-ask-file-name
87+
(read-string "Rust Playground filename: ")) ("snippet"))))
88+
(concat (rust-playground-snippet-unique-dir file-name) "/" file-name ".rs"))))
8789

8890
(defun rust-playground-exec ()
89-
"Save the buffer then runs Rust compiler for executing the code."
91+
"Save the buffer then run Rust compiler for executing the code."
9092
(interactive)
9193
(make-local-variable 'compile-command)
9294
(let ((snippet-file buffer-file-name))
93-
(save-buffer t)
94-
(compile (concat rust-playground-bin " " (shell-quote-argument snippet-file) " -o snippet && "
95-
(file-name-directory snippet-file) "snippet"))))
95+
(save-buffer t)
96+
(compile "cargo build")))
9697

9798
;;;###autoload
9899
(defun rust-playground ()
@@ -101,21 +102,21 @@ By default confirmation required."
101102
(let ((snippet-file-name (rust-playground-snippet-file-name)))
102103
(switch-to-buffer (create-file-buffer snippet-file-name))
103104
(add-hook 'kill-buffer-hook 'rust-playground-on-buffer-kill nil t)
104-
(rust-playground-insert-template-head "snippet of code")
105-
(insert "fn main() {
105+
(rust-playground-insert-template-head "snippet of code")
106+
(insert "fn main() {
106107
107108
println!(\"Results:\")
108109
109110
}")
110-
(backward-char 3)
111-
(rust-mode)
112-
(rust-playground-mode)
113-
(set-visited-file-name snippet-file-name t)))
111+
(backward-char 3)
112+
(rust-mode)
113+
(rust-playground-mode)
114+
(set-visited-file-name snippet-file-name t)))
114115

115-
; remove compiled binary from snippet dir but not touch source files
116+
; remove compiled binary from snippet dir but not touch source files ;
116117
(defun rust-playground-on-buffer-kill ()
117118
(if (string-match-p (file-truename rust-playground-basedir) (file-truename (buffer-file-name)))
118-
(delete-file (concat (file-name-directory (buffer-file-name)) "snippet"))))
119+
(delete-file (concat (file-name-directory (buffer-file-name)) "snippet"))))
119120

120121
(defun rust-playground-insert-template-head (description)
121122
(insert "// -*- mode:rust;mode:rust-playground -*-
@@ -128,20 +129,20 @@ By default confirmation required."
128129
"))
129130

130131
;;;###autoload
131-
(defun rust-playground-rm ()
132+
(defun rust-playground-rm ()
132133
"Remove files of the current snippet together with directory of this snippet."
133134
(interactive)
134135
(if (rust-playground-inside)
135136
(if (or (not rust-playground-confirm-deletion)
136-
(y-or-n-p (format "Do you want delete whole snippet dir %s? "
137-
(file-name-directory (buffer-file-name)))))
138-
(progn
139-
(save-buffer)
140-
(delete-directory (file-name-directory (buffer-file-name)) t t)
141-
(remove-hook 'kill-buffer-hook 'rust-playground-on-buffer-kill t)
142-
(kill-buffer)))
143-
(message "Won't delete this! Because %s is not under the path %s. Remove the snippet manually!"
144-
(buffer-file-name) rust-playground-basedir)))
137+
(y-or-n-p (format "Do you want delete whole snippet dir %s? "
138+
(file-name-directory (buffer-file-name)))))
139+
(progn
140+
(save-buffer)
141+
(delete-directory (file-name-directory (buffer-file-name)) t t)
142+
(remove-hook 'kill-buffer-hook 'rust-playground-on-buffer-kill t)
143+
(kill-buffer)))
144+
(message "Won't delete this! Because %s is not under the path %s. Remove the snippet manually!"
145+
(buffer-file-name) rust-playground-basedir)))
145146

146147
;; ;;;###autoload
147148
;; (defun rust-playground-download (url)
@@ -157,11 +158,11 @@ By default confirmation required."
157158
;; (copy-to-buffer buffer (point) (point-max))
158159
;; (kill-buffer)
159160
;; (with-current-buffer buffer
160-
;; (goto-char (point-min))
161-
;; (rust-playground-insert-template-head (concat url " imported"))
162-
;; (rust-mode)
163-
;; (rust-playground-mode)
164-
;; (set-visited-file-name snippet-file-name t)
161+
;; (goto-char (point-min))
162+
;; (rust-playground-insert-template-head (concat url " imported"))
163+
;; (rust-mode)
164+
;; (rust-playground-mode)
165+
;; (set-visited-file-name snippet-file-name t)
165166
;; (switch-to-buffer buffer)))))
166167

167168
;; (defun rust-playground-upload ()
@@ -182,7 +183,7 @@ By default confirmation required."
182183
(defun rust-playground-inside ()
183184
"It checks that minor mode is rusl-playground and buffer file placed under default directory."
184185
(if (string-match-p (file-truename rust-playground-basedir) (file-truename (buffer-file-name)))
185-
(bound-and-true-p rust-playground-mode)))
186+
(bound-and-true-p rust-playground-mode)))
186187

187188
(provide 'rust-playground)
188189
;;; rust-playground.el ends here

0 commit comments

Comments
 (0)