Emacs Ruby-mode shortcut for compiling / running?

I am a little versed in Emacs, as I used it to write abstracts in AUCTex.

However, this time, trying to write some simple ruby ​​program, mainly for learning, I searched Google Ruby in Emacs and could not find what I was looking for.

Based on what I read so far, I know that Emacs (23.3.5), which I use, has a built-in ruby ​​mode that should support syntax highlighting, auto indentation, etc. But what about a shortcut key for debugging / launching, something like Mode Compile ?

+4
source share
3 answers

I suggest using quickrun.el , which is supported by me.

quickrun.el is an extension for performing buffer editing. quickrun.el supports many programming languages ​​and markup languages, of course it supports Ruby.

You download quickrun.el at the following URL.

https://raw.github.com/syohex/emacs-quickrun/master/quickrun.el

And you add quickrun.el, following the setup in your configuration file and evaluating it (or reloading Emacs).

(add-to-list 'load-path "~/.emacs.d/elisp") ;; If you install quickrun.el to ~/.emacs.d/elisp (require 'quickrun) 

Now you can use the following command to execute the current buffer.

 Mx quickrun 

You can use the current current compilation buffer (do not execute).

 Mx quickrun-compile-only 

If you often use the quickrun command, you should assign key bindings, such as the following.

 (global-set-key (kbd "<f7>") 'quickrun) (global-set-key (kbd "<f8>") 'quickrun-compile-only) 

Please see the github page if you know more information about quickrun.el.

thanks

+3
source

I would suggest using inf-ruby to get an IRB session inside Emacs. Then you can use for example. Cc Cl to call inf-ruby-load-file to load your buffer inside an IRB session.

Alternatively, you can also use Flymake to constantly syntax your buffer against ruby -c . Here are 3 functions that I took from emacs-starter-kit :

 (defun flymake-ruby-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) ;; Invoke ruby with '-c' to get syntax checking (list "ruby" (list "-c" local-file)))) (defun flymake-ruby-enable () (when (and buffer-file-name (file-writable-p (file-name-directory buffer-file-name)) (file-writable-p buffer-file-name) (if (fboundp 'tramp-list-remote-buffers) (not (subsetp (list (current-buffer)) (tramp-list-remote-buffers))) t)) (local-set-key (kbd "Cc d") 'flymake-display-err-menu-for-current-line) (flymake-mode t))) (eval-after-load 'ruby-mode '(progn (require 'flymake) (push '(".+\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks) (push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks) (push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3) flymake-err-line-patterns) (add-hook 'ruby-mode-hook 'flymake-ruby-enable))) 

In addition, I use the following function to display Flymake errors at a point:

 ;; Flymake errors at point from Dave Love on gnu.emacs.help: (defun my-flymake-show-help () (when (get-char-property (point) 'flymake-overlay) (let ((help (get-char-property (point) 'help-echo))) (if help (message "%s" help))))) (add-hook 'post-command-hook 'my-flymake-show-help) 

All of the above together creates a very decent Ruby Emacs experience.

+3
source

You can run the ruby ​​program with Mx compile and get "ruby -w your_program".

The result will be similar to compilation output, so you can click on the errors to jump to the line.

It seems that compilation mode also supports ruby ​​mode.

0
source

Source: https://habr.com/ru/post/1392278/


All Articles