2015-06-10 16:44:30 +00:00
#+TITLE : Ruby contribution layer for Spacemacs
2015-11-08 18:04:44 +00:00
#+HTML_HEAD_EXTRA : <link rel="stylesheet" type="text/css" href="../../../css/readtheorg.css" />
2015-06-10 16:44:30 +00:00
2015-07-04 03:33:13 +00:00
[[file:img/ruby.png ]]
2015-06-10 16:44:30 +00:00
2015-10-30 11:20:58 +00:00
* Table of Contents :TOC_4_org:noexport:
- [[Description ][Description ]]
- [[Install ][Install ]]
- [[Prerequisites ][Prerequisites ]]
- [[Ruby version management ][Ruby version management ]]
2015-11-27 05:25:55 +00:00
- [[Test runner ][Test runner ]]
2015-10-30 11:20:58 +00:00
- [[Key bindings ][Key bindings ]]
- [[Ruby (enh-ruby-mode, robe, inf-ruby, ruby-tools) ][Ruby (enh-ruby-mode, robe, inf-ruby, ruby-tools) ]]
2015-11-27 04:55:43 +00:00
- [[RuboCop ][RuboCop ]]
2015-11-27 05:25:55 +00:00
- [[Tests ][Tests ]]
- [[RSpec-mode ][RSpec-mode ]]
- [[Ruby-test-mode ][Ruby-test-mode ]]
2015-06-10 16:44:30 +00:00
* Description
2015-10-15 20:52:43 +00:00
This layer provides support for the Ruby language with [[https://github.com/zenspider/enhanced-ruby-mode ][enh-ruby-mode ]] and [[https://github.com/dgutov/robe ][robe-mode ]].
Optionally Enh Ruby Mode can be replaced with the built-in Emacs Ruby Mode.
2015-06-10 16:44:30 +00:00
* Install
To use this contribution add it to your =~/.spacemacs=
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(ruby))
#+END_SRC
2015-10-15 20:52:43 +00:00
This layer supports two different Ruby modes: Emacs' built-in Ruby Mode and
2015-10-19 04:10:32 +00:00
[[https://github.com/zenspider/enhanced-ruby-mode ][enh-ruby-mode ]]. By default the built-in Ruby mode is enabled. To switch to the
=enh-ruby-mode= set =ruby-enable-enh-ruby-mode= to t:
2015-10-15 20:52:43 +00:00
#+BEGIN_SRC emacs-lisp
2015-10-19 04:10:32 +00:00
(defun dotspacemacs-configuration-layers ()
'((ruby :variables ruby-enable-enh-ruby-mode t)))
2015-10-15 20:52:43 +00:00
#+END_SRC
2015-06-10 16:44:30 +00:00
** Prerequisites
Some of the advanced features supported by this layer depend on external gems
that need to be installed in the context of your project (see below for guidance
based on your version manager):
2015-06-10 21:16:01 +00:00
- =pry= and =pry-doc= are required for *jump to definition* and *code documentation* (=robe-mode= )
- =ruby_parser= is required for *goto-step_definition* in =feature-mode=
2015-09-08 23:03:42 +00:00
- =rubocop= is required for rubocop integration
2015-06-10 16:44:30 +00:00
You can install the gems in the context of your current project by
adding them to the =Gemfile= , e.g.:
#+BEGIN_SRC ruby
gem 'pry'
#+END_SRC
or on the command line (please refer to your ruby version manager
specific documentation for details and caveats):
#+BEGIN_SRC sh
2015-06-10 21:16:01 +00:00
gem install pry
2015-06-10 16:44:30 +00:00
#+END_SRC
** Ruby version management
This layer supports the use of [[https://rvm.io/ ][RVM ]] and [[https://github.com/sstephenson/rbenv ][Rbenv ]].
To enable it, set the =ruby-version-manager= var in your =~/.spacemacs= :
#+BEGIN_SRC emacs-lisp
2015-11-27 05:25:55 +00:00
(defun dotspacemacs-configuration-layers ()
'((ruby :variables ruby-version-manager 'rbenv)))
2015-06-10 16:44:30 +00:00
#+END_SRC
Possible values are =rbenv= and =rvm= .
2015-11-27 05:25:55 +00:00
** Test runner
This layer supports both =RSpec= and =ruby-test= test runners (frameworks).
By default =ruby-test= is used, to change to another frameworks set
the layer variable =ruby-test-runner= .
Example to set the test runner to =RSpec= :
2015-11-10 23:42:33 +00:00
#+BEGIN_SRC emacs-lisp
2015-11-27 05:25:55 +00:00
(defun dotspacemacs-configuration-layers ()
'((ruby :variables ruby-test-runner 'rspec)))
2015-11-10 23:42:33 +00:00
#+END_SRC
2015-11-27 05:25:55 +00:00
=Tip:= You can enable different test runners for different projects by using
directory local variables.
2015-06-10 16:44:30 +00:00
* Key bindings
2015-07-29 09:58:47 +00:00
** Ruby (enh-ruby-mode, robe, inf-ruby, ruby-tools)
2015-06-10 16:44:30 +00:00
2015-10-15 20:52:43 +00:00
| Key binding | Description |
|-------------+------------------------------------------------------|
| ~SPC m '~ | toggle quotes of current string (only built-in mode) |
| ~SPC m {~ | toggle style of current block (only built-in mode) |
| ~SPC m g g~ | go to definition (robe-jump) |
| ~SPC m h d~ | go to Documentation |
| ~SPC m s f~ | send function definition |
| ~SPC m s F~ | send function definition and switch to REPL |
| ~SPC m s i~ | start REPL |
| ~SPC m s r~ | send region |
| ~SPC m s R~ | send region and switch to REPL |
| ~SPC m s s~ | switch to REPL |
| ~SPC m x '~ | Change symbol or " string to ' |
| ~SPC m x "~ | Change symbol or ' string to " |
| ~SPC m x :~ | Change string to symbol |
| ~%~ | [[https://github.com/redguardtoo/evil-matchit][evil-matchit]] jumps between blocks |
2015-06-10 16:44:30 +00:00
2015-11-27 05:25:55 +00:00
** RuboCop
| Key binding | Description |
|---------------+------------------------------------------------------|
| ~SPC m r r f~ | Runs RuboCop on the currently visited file |
| ~SPC m r r F~ | Runs auto-correct on the currently visited file |
| ~SPC m r r d~ | Prompts from a directory on which to run RuboCop |
| ~SPC m r r D~ | Prompts for a directory on which to run auto-correct |
| ~SPC m r r p~ | Runs RuboCop on the entire project |
| ~SPC m r r P~ | Runs auto-correct on the project |
** Tests
*** RSpec-mode
When =ruby-test-runner= equals =rspec= .
2015-11-10 23:42:33 +00:00
| Key binding | Description |
|-------------+----------------------|
| ~SPC m t a~ | run all specs |
2015-11-27 05:25:55 +00:00
| ~SPC m t l~ | run last failed spec |
2015-11-10 23:42:33 +00:00
| ~SPC m t r~ | re-run last spec |
| ~SPC m t t~ | run spec at pointer |
2015-11-27 05:25:55 +00:00
*** Ruby-test-mode
When =ruby-test-runner= equals =ruby-test= .
2015-06-10 16:44:30 +00:00
| Key binding | Description |
|-------------+---------------------|
| ~SPC m t b~ | run test file |
| ~SPC m t t~ | run test at pointer |