An enhanced ruby-mode for Emacs that uses Ripper in ruby 1.9.2 to highlight and indent the source code
Emacs Lisp Ruby
Pull request Compare This branch is 154 commits ahead of jacott:master.
Latest commit 6d13ecc Apr 18, 2017 @zenspider Hopefully fixes enh-ruby-add-log-current-method.
This works for both forms of prefixed class methods and regular
instance methods. It does NOT work with `class << self` blocks. I
don't use them. PRs welcome but only if reasonable.

README.rdoc

Enhanced Ruby Mode

Description

Enhanced Ruby Mode replaces the emacs ruby mode that comes with ruby.

It uses the Ripper class found in ruby 1.9.2 (and later) to parse and indent the source code. As a consquence only ruby 1.9.2 (or later) syntax is parsed correctly.

Syntax checking is also performed.

TODO

  • Optimisation; currently parses and fontifies whole buffer for most modifications - it still appears to run fast enough on large files.

  • Suggestions?

Synopsis

  • Enhanced Ruby Mode is intallable via el-get and Melpa, where its package name is enh-ruby-mode.

  • For manual installation, add the following file to your init file.

    (add-to-list 'load-path "(path-to)/Enhanced-Ruby-Mode") ; must be added after any path containing old ruby-mode
    (autoload 'enh-ruby-mode "enh-ruby-mode" "Major mode for ruby files" t)
    (add-to-list 'auto-mode-alist '("\\.rb$" . enh-ruby-mode))
    (add-to-list 'interpreter-mode-alist '("ruby" . enh-ruby-mode))
    
    ;; optional
    
    (setq enh-ruby-program "(path-to-ruby1.9)/bin/ruby") ; so that still works if ruby points to ruby1.8
  • Enhanced Ruby Mode defines its own specific faces with the hook erm-define-faces. If your theme is already defining those faces, to not overwrite them, just remove the hook with:

    (remove-hook 'enh-ruby-mode-hook 'erm-define-faces)

Existing ruby-mode hooks

You may have existing lines in your emacs config that add minor modes based on ruby mode, like this:

(add-hook 'ruby-mode-hook 'robe-mode)
(add-hook 'ruby-mode-hook 'yard-mode)

For these to work with enh-ruby-mode, you need to add hooks to the enh-ruby-mode minor mode:

(add-hook 'enh-ruby-mode-hook 'robe-mode)
(add-hook 'enh-ruby-mode-hook 'yard-mode)

Load enh-ruby-mode for Ruby files

To use enh-ruby-mode for .rb add the following to your init file:

(add-to-list 'auto-mode-alist '("\\.rb$" . enh-ruby-mode))

To use enh-ruby-mode for all common Ruby files and the following to your init file:

(add-to-list 'auto-mode-alist
             '("\\(?:\\.rb\\|ru\\|rake\\|thor\\|jbuilder\\|gemspec\\|podspec\\|/\\(?:Gem\\|Rake\\|Cap\\|Thor\\|Vagrant\\|Guard\\|Pod\\)file\\)\\'" . enh-ruby-mode))

Requirements

  • ruby 1.9.2 (or later)

Install

  • git clone git@github.com:zenspider/Enhanced-Ruby-Mode.git

Development

Developing requires minitest 5.x gem.

Testing parser:

ruby test/test_erm_buffer.rb

Sorry, no test suite for enh-ruby-mode.el

Tests for Emacs Lisp require ERT. It is built-in since Emacs 24.1.

Credits

Jell (Jean-Louis Giordano) github.com/Jell

Improved UTF-8 support