My Ruby (on Rails) Setup in Emacs
Emacs is the editor of choice for many Ruby on Rails developers and I am no exception.
While support for Ruby is somehow lacking in some packages (most notably Semantic Mode and Speedbar), there are many packages one can use to simplify and speed software development up.
However, I like to keep things simple and most of the time I stick with the “basic” machinery.
This is the setup I am currently using, in case you want to try it out:
- Major modes The following is stuff super-consolidated in my routine. I
mainly rely on the syntax highlighting and code indentation features. I
have some complaints with some indentation choices made by Ruby and Web Mode
(most notably: indentation of function arguments spanning multiple lines for
Ruby; HTML code is not indented when embedded in Ruby blocks for Web mode),
but, overall, the experience is extremely good. The mode I use less often
is Po mode since I prefer to use a GUI client (GNOME Translation Editor,
Poedit):
- Ruby Mode
- Yaml Mode
- Web Mode
- Rainbow mode
- Po mode
- Management of Ruby versions and
inferior… ahem … superior Ruby shell. This is also super-standard. Here I only want to remark that I find chruby far superior to any other tool to control Ruby versions. - Code Browsing and Navigation
- SrSpeedbar
- imenu list. This is something relatively new for me. I’ll see whether it will stick in my routine.
- Code folding
- I sometimes fold code with Yafolding and, more often, with the
function offered by Web Mode (
M-x web-mode-fold-or-unfold
, bound toC-cC-f
), since I find more useful folding HTML than Ruby code.
- I sometimes fold code with Yafolding and, more often, with the
function offered by Web Mode (
- Searching and Replacing in projects Here I tend to indulge on the very
basic stuff. I use:
- The standard project functions provided by Emacs (e.g.,
M-x project-search
) for replacing across files in a project. M-x grep
andM-x occur
for finding symbols- I sometimes try with
ctags
, but I find the machinery a bit clumsy, although very effective when I remember to update and load the TAGS file.
- The standard project functions provided by Emacs (e.g.,
- Syntax checking The following are packages I decided to try in 2022. At first glance they are extremely useful and simple to use. I hope I will manage to add them to my routine:
- Auto completion Most of the time I just type (and make mistakes), less
frequently use
M-x dabbrev-expand
, and recently decided to try with Company Mode, a more structured solution. Let us see whether Company mode will enhance my routine. - Version Control Most of the time I stick with Gitg, a GUI tool developed
for the Gnome environment. For simpler tasks, I use
M-x magit
. There was I time when I used exclusively magit. However, I ended up preferring the visual advantage provided by a GUI to the faster speed I could muster using a text tool. I have also tried the default functions offered by Emacs, which are quite nice, although I find the workflow they seem to impose a bit too rigid. For instance it is impossible to add a new file to the stage if you already staged other already-known files; you need to go back, add the files first and then you can stage the known and new files.
Other stuff which has not yet entered my routine:
- Projectile
- Robe
- Rails Log Mode
- Yasnippet, extremely useful, but which I use every once in a while, preferring Copy and Paste.