1

I am trying to use following code:

(defun rust-save-and-build (mode)
  (interactive)
  (save-buffer)

  (setq tmp (shell-command-to-string (format "cygpath.exe -m %s"
                     (buffer-file-name)))

(if (locate-dominating-file buffer-file-name "Cargo.toml")
        (compile mode)

  (compile
   (format "rustc %s %s.exe"
       tmp
       (file-name-sans-extension tmp))))))



(defun rust-cmd-run ()
  (interactive)
  (rust-save-and-build "cargo run"))

(defun rust-cmd-build ()
  (interactive)
  (rust-save-and-build "cargo build"))

(defun rust-cmd-test ()
  (interactive)
  (rust-save-and-build "cargo test"))



(add-hook 'rust-mode-hook
  (lambda ()
    (define-key rust-mode-map (kbd "<f5>") 'rust-cmd-run)))

(add-hook 'rust-mode-hook
  (lambda ()
    (define-key rust-mode-map (kbd "<f6>") 'rust-cmd-build)))

(add-hook 'rust-mode-hook
  (lambda ()
    (define-key rust-mode-map (kbd "<f7>") 'rust-cmd-test)))

but get "Wrong type argument: symbolp" error when use f-keys. The debug message is:

 Debugger entered--Lisp error: (wrong-type-argument symbolp (if (locate-dominating-file buffer-file-name "Cargo.toml") (compile mode) (compile (format "rustc %s %s.exe" tmp (file-name-sans-extension tmp)))))
 (setq tmp (shell-command-to-string (format "cygpath.exe -m %s" (buffer-file-name))) (if (locate-dominating-file buffer-file-name "Cargo.toml") (compile mode) (compile (format "rustc %s %s.exe" tmp (file-name-sans-extension tmp)))))
  rust-save-and-build("cargo run")
  rust-cmd-run()
  call-interactively(rust-cmd-run nil nil)
  command-execute(rust-cmd-run)

NB that rust-save-and-build function works perfectly without argument.

2

Indent your code properly and you will see that you did not close your setq:

(defun rust-save-and-build (mode)
  (interactive)
  (save-buffer)

  (setq tmp (shell-command-to-string (format "cygpath.exe -m %s"
                                             (buffer-file-name)))

        (if (locate-dominating-file buffer-file-name "Cargo.toml")
            (compile mode)

          (compile
           (format "rustc %s %s.exe"
                   tmp
                   (file-name-sans-extension tmp))))))

You probably wanted something like this:

(defun rust-save-and-build (mode)
  (interactive)
  (save-buffer)

  (setq tmp (shell-command-to-string (format "cygpath.exe -m %s"
                                             (buffer-file-name))))

  (if (locate-dominating-file buffer-file-name "Cargo.toml")
      (compile mode)

    (compile
     (format "rustc %s %s.exe"
             tmp
             (file-name-sans-extension tmp)))))

Remember that show-paren-mode is your friend, as are TAB and C-M-q. Get to know the keys bound in Emacs-Lisp mode - use C-h m and C-h b in a buffer with that mode. Or if you are doing this in another mode (e.g. in buffer *scratch*) then use them there, to the same effect.

  • Thank you! My fault. I though that setq creates namespace with variable. Many thanks for shortcuts. – DoSofRedRiver Apr 5 '16 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.