      (define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
      (define-key ruby-mode-map (kbd "TAB") 'indent-for-tab-command)))
 
+;; Stupidly the non-bundled ruby-mode isn't a derived mode of
+;; prog-mode: we run the latter's hooks anyway in that case.
+(add-hook 'ruby-mode-hook
+          (lambda ()
+            (unless (derived-mode-p 'prog-mode)
+              (run-hooks 'prog-mode-hook))))
 
-;;----------------------------------------------------------------------------
-;; Ruby - flymake
-;;----------------------------------------------------------------------------
+
++
+;;; Inferior ruby
+(require-package 'inf-ruby)
+(autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process")
+
+
++
+;;; Ruby compilation
+(require-package 'ruby-compilation)
+
+(eval-after-load 'ruby-mode
+ '(let ((m ruby-mode-map))
+    (define-key m [S-f7] 'ruby-compilation-this-buffer)
+    (define-key m [f7] 'ruby-compilation-this-test)
+    (define-key m [f6] 'recompile)))
+
+
++
+;;; Ruby flymake
+(require-package 'flymake-ruby)
 (add-hook 'ruby-mode-hook 'flymake-ruby-load)
 
 
-;;----------------------------------------------------------------------------
-;; Ruby - robe
-;;----------------------------------------------------------------------------
++
+;;; Robe
+(require-package 'robe)
 (add-hook 'ruby-mode-hook 'robe-mode)
 (add-hook 'robe-mode-hook
           (lambda ()

;;          :delimiter-mode nil)))
;;      (mmm-add-mode-ext-class 'ruby-mode "\\.rb\\'" 'ruby-heredoc-sql)))


;;----------------------------------------------------------------------------
;; Ruby - compilation
;;----------------------------------------------------------------------------

; run the current buffer using Shift-F7
(add-hook 'ruby-mode-hook (lambda () (local-set-key [S-f7] 'ruby-compilation-this-buffer)))
; run the current test function using F8 key
(add-hook 'ruby-mode-hook (lambda () (local-set-key [f7] 'ruby-compilation-this-test)))

(add-hook 'ruby-mode-hook (lambda () (local-set-key [f6] 'recompile)))




;; Stupidly the non-bundled ruby-mode isn't a derived mode of
;; prog-mode: we run the latter's hooks anyway in that case.
(add-hook 'ruby-mode-hook
          (lambda ()
            (unless (derived-mode-p 'prog-mode)
              (run-hooks 'prog-mode-hook))))


(provide 'init-ruby-mode)

;;; Basic ruby setup
(require-package 'ruby-mode)
(require-package 'ruby-hash-syntax)

(add-auto-mode 'ruby-mode
               "Rakefile\\'" "\\.rake\\'" "\.rxml\\'"
               "\\.rjs\\'" ".irbrc\\'" "\.builder\\'" "\\.ru\\'"
               "\\.gemspec\\'" "Gemfile\\'" "Kirkfile\\'")

(setq ruby-use-encoding-map nil)

