Created
October 25, 2013 19:49
-
-
Save gnufied/7160799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq enh-ruby-program "/home/gnufied/.rbenv/versions/1.9.3-p448/bin/ruby") | |
(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 'auto-mode-alist '("\\.rake$" . enh-ruby-mode)) | |
(add-to-list 'auto-mode-alist '("Rakefile$" . enh-ruby-mode)) | |
(add-to-list 'auto-mode-alist '("\\.gemspec$" . enh-ruby-mode)) | |
(add-to-list 'auto-mode-alist '("\\.ru$" . enh-ruby-mode)) | |
(add-to-list 'auto-mode-alist '("Gemfile$" . enh-ruby-mode)) | |
(add-to-list 'interpreter-mode-alist '("ruby" . enh-ruby-mode)) | |
(setq enh-ruby-bounce-deep-indent t) | |
(setq enh-ruby-hanging-brace-indent-level 2) | |
(require 'cl) ; If you don't have it already | |
(defun* get-closest-gemfile-root (&optional (file "Gemfile")) | |
"Determine the pathname of the first instance of FILE starting from the current directory towards root. | |
This may not do the correct thing in presence of links. If it does not find FILE, then it shall return the name | |
of FILE in the current directory, suitable for creation" | |
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly | |
(loop | |
for d = default-directory then (expand-file-name ".." d) | |
if (file-exists-p (expand-file-name file d)) | |
return d | |
if (equal d root) | |
return nil))) | |
(require 'compile) | |
(defun rspec-compile-file () | |
(interactive) | |
(compile (format "cd %s;bundle exec rspec %s" | |
(get-closest-gemfile-root) | |
(file-relative-name (buffer-file-name) (get-closest-gemfile-root)) | |
) t)) | |
(defun rspec-compile-on-line () | |
(interactive) | |
(compile (format "cd %s;bundle exec rspec %s -l %s" | |
(get-closest-gemfile-root) | |
(file-relative-name (buffer-file-name) (get-closest-gemfile-root)) | |
(line-number-at-pos) | |
) t)) | |
(add-hook 'enh-ruby-mode-hook | |
(lambda () | |
(local-set-key (kbd "C-c l") 'rspec-compile-on-line) | |
(local-set-key (kbd "C-c k") 'rspec-compile-file) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment