From d5ef2070289d0e254e932cf5ed9d06fbdfdb4264 Mon Sep 17 00:00:00 2001 From: David Corking Date: Thu, 1 Mar 2018 16:08:32 +0000 Subject: [PATCH 1/2] 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) ``` --- rust-playground.el | 63 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/rust-playground.el b/rust-playground.el index 3c4d659..4f80ba6 100644 --- a/rust-playground.el +++ b/rust-playground.el @@ -80,19 +80,18 @@ By default confirmation required." :keymap '(([C-return] . rust-playground-exec))) (defun rust-playground-snippet-file-name(&optional snippet-name) - (setq-local rust-playground-current-snippet-file (let ((file-name (cond (snippet-name) - (rust-playground-ask-file-name - (read-string "Rust Playground filename: ")) ("snippet")))) - (concat (rust-playground-snippet-unique-dir file-name) "/" file-name ".rs")))) + (setq-local rust-playground-current-snippet-file (let ((file-name (cond (snippet-name) + (rust-playground-ask-file-name + (read-string "Rust Playground filename: ")) ("snippet")))) + (concat (rust-playground-snippet-unique-dir file-name) "/" file-name ".rs")))) (defun rust-playground-exec () - "Save the buffer then runs Rust compiler for executing the code." + "Save the buffer then run Rust compiler for executing the code." (interactive) (make-local-variable 'compile-command) (let ((snippet-file buffer-file-name)) - (save-buffer t) - (compile (concat rust-playground-bin " " (shell-quote-argument snippet-file) " -o snippet && " - (file-name-directory snippet-file) "snippet")))) + (save-buffer t) + (compile "cargo build"))) ;;;###autoload (defun rust-playground () @@ -101,21 +100,21 @@ By default confirmation required." (let ((snippet-file-name (rust-playground-snippet-file-name))) (switch-to-buffer (create-file-buffer snippet-file-name)) (add-hook 'kill-buffer-hook 'rust-playground-on-buffer-kill nil t) - (rust-playground-insert-template-head "snippet of code") -(insert "fn main() { + (rust-playground-insert-template-head "snippet of code") + (insert "fn main() { println!(\"Results:\") }") -(backward-char 3) -(rust-mode) -(rust-playground-mode) -(set-visited-file-name snippet-file-name t))) + (backward-char 3) + (rust-mode) + (rust-playground-mode) + (set-visited-file-name snippet-file-name t))) -; remove compiled binary from snippet dir but not touch source files +; remove compiled binary from snippet dir but not touch source files ; (defun rust-playground-on-buffer-kill () (if (string-match-p (file-truename rust-playground-basedir) (file-truename (buffer-file-name))) - (delete-file (concat (file-name-directory (buffer-file-name)) "snippet")))) + (delete-file (concat (file-name-directory (buffer-file-name)) "snippet")))) (defun rust-playground-insert-template-head (description) (insert "// -*- mode:rust;mode:rust-playground -*- @@ -128,20 +127,20 @@ By default confirmation required." ")) ;;;###autoload -(defun rust-playground-rm () +(defun rust-playground-rm () "Remove files of the current snippet together with directory of this snippet." (interactive) (if (rust-playground-inside) (if (or (not rust-playground-confirm-deletion) - (y-or-n-p (format "Do you want delete whole snippet dir %s? " - (file-name-directory (buffer-file-name))))) - (progn - (save-buffer) - (delete-directory (file-name-directory (buffer-file-name)) t t) - (remove-hook 'kill-buffer-hook 'rust-playground-on-buffer-kill t) - (kill-buffer))) - (message "Won't delete this! Because %s is not under the path %s. Remove the snippet manually!" - (buffer-file-name) rust-playground-basedir))) + (y-or-n-p (format "Do you want delete whole snippet dir %s? " + (file-name-directory (buffer-file-name))))) + (progn + (save-buffer) + (delete-directory (file-name-directory (buffer-file-name)) t t) + (remove-hook 'kill-buffer-hook 'rust-playground-on-buffer-kill t) + (kill-buffer))) + (message "Won't delete this! Because %s is not under the path %s. Remove the snippet manually!" + (buffer-file-name) rust-playground-basedir))) ;; ;;;###autoload ;; (defun rust-playground-download (url) @@ -157,11 +156,11 @@ By default confirmation required." ;; (copy-to-buffer buffer (point) (point-max)) ;; (kill-buffer) ;; (with-current-buffer buffer -;; (goto-char (point-min)) -;; (rust-playground-insert-template-head (concat url " imported")) -;; (rust-mode) -;; (rust-playground-mode) -;; (set-visited-file-name snippet-file-name t) +;; (goto-char (point-min)) +;; (rust-playground-insert-template-head (concat url " imported")) +;; (rust-mode) +;; (rust-playground-mode) +;; (set-visited-file-name snippet-file-name t) ;; (switch-to-buffer buffer))))) ;; (defun rust-playground-upload () @@ -182,7 +181,7 @@ By default confirmation required." (defun rust-playground-inside () "It checks that minor mode is rusl-playground and buffer file placed under default directory." (if (string-match-p (file-truename rust-playground-basedir) (file-truename (buffer-file-name))) - (bound-and-true-p rust-playground-mode))) + (bound-and-true-p rust-playground-mode))) (provide 'rust-playground) ;;; rust-playground.el ends here From 44320deb88bd9e2b282b19e59c42dd16f7beeb11 Mon Sep 17 00:00:00 2001 From: David Corking Date: Thu, 1 Mar 2018 16:17:05 +0000 Subject: [PATCH 2/2] Try to improve layout of current-snippet-file code --- rust-playground.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rust-playground.el b/rust-playground.el index 4f80ba6..b7036d9 100644 --- a/rust-playground.el +++ b/rust-playground.el @@ -80,10 +80,12 @@ By default confirmation required." :keymap '(([C-return] . rust-playground-exec))) (defun rust-playground-snippet-file-name(&optional snippet-name) - (setq-local rust-playground-current-snippet-file (let ((file-name (cond (snippet-name) - (rust-playground-ask-file-name - (read-string "Rust Playground filename: ")) ("snippet")))) - (concat (rust-playground-snippet-unique-dir file-name) "/" file-name ".rs")))) + (setq-local rust-playground-current-snippet-file + (let ((file-name + (cond (snippet-name) + (rust-playground-ask-file-name + (read-string "Rust Playground filename: ")) ("snippet")))) + (concat (rust-playground-snippet-unique-dir file-name) "/" file-name ".rs")))) (defun rust-playground-exec () "Save the buffer then run Rust compiler for executing the code."