[已解决] Spacemacs 怎样运行 buffer 中的 ruby 代码?

spacemacs 的 ruby layer 怎么运行打开的 ruby 文件,我看见 python layer 可以使用 ‘SPC m c c’直接运行,但是 ruby layer 好像没有这个功能?

bundle init
bundle

SPC m b s

call: ruby-send-buffer,或者其他的 ruby-send-xxxxxxx commands

你可以自己做个 key binding

试试这一段代码。 我改了一点 @子龙山人 配置的一段代码。 不止 ruby 可以用哦。

(defun zilongshanren/run-current-file ()
  "Execute the current file.
For example, if the current buffer is the file x.py, then it'll call 「python x.py」 in a shell.
The file can be emacs lisp, php, perl, python, ruby, javascript, bash, ocaml, Visual Basic.
File suffix is used to determine what program to run.

If the file is modified, ask if you want to save first.

URL `http://ergoemacs.org/emacs/elisp_run_current_file.html'
version 2015-08-21"
  (interactive)
  (let* (
         (ξsuffix-map
          ;; (‹extension› . ‹shell program name›)
          `(
            ("php" . "php")
            ("pl" . "perl")
            ("py" . "python")
            ("py3" . ,(if (string-equal system-type "windows-nt") "c:/Python32/python.exe" "python3"))
            ("rb" . "ruby")
            ("js" . "node") ; node.js
            ("sh" . "bash")
            ;; ("clj" . "java -cp /home/xah/apps/clojure-1.6.0/clojure-1.6.0.jar clojure.main")
            ("ml" . "ocaml")
            ("vbs" . "cscript")
            ("tex" . "pdflatex")
            ("lua" . "lua")
            ("cpp" . "make && ./runcpp")  ; compile for c++. and you need Makefile in dir  by noclyt 2016.7.8
            ;; ("pov" . "/usr/local/bin/povray +R2 +A0.1 +J1.2 +Am2 +Q9 +H480 +W640")
            ))
         (ξfname (buffer-file-name))
         (ξfSuffix (file-name-extension ξfname))
         (ξprog-name (cdr (assoc ξfSuffix ξsuffix-map)))
         (ξcmd-str (if (string-equal ξfSuffix "cpp")
                       (concat ξprog-name "  ")
                     (concat ξprog-name " \""   ξfname "\""))))

    (when (buffer-modified-p)
      (when (y-or-n-p "Buffer modified. Do you want to save first?")
        (save-buffer)))

    (if (string-equal ξfSuffix "el") ; special case for emacs lisp
        (load ξfname)
      (if ξprog-name
          (progn
            (message "Running…")
            (async-shell-command ξcmd-str "*zilongshanren/run-current-file output*"))
        (message "No recognized program file suffix for this file.")))))

对这个函数,自己做个 key-binding

(global-set-key (kbd "<f8>") 'zilongshanren/run-current-file)
2 个赞

谢楼上两位,我最后用quickrun解决的

还是quickrun给力。