Permalink
Browse files

rails-ruby extensions are optional and not enabled by default

Many don't desire the modifications rails-minor-mode makes on ruby-mode.
It seems to be reaching out of it's scope.  Rails-minor-mode should
focus on providing helpers that specifically contribute to rails, and
not needlessly modifying behavior of ruby-mode.  Extensions that modify
ruby-mode should belong to another package, or as an optional include.
  • Loading branch information...
timcharper committed Jan 16, 2011
1 parent 97cf623 commit fddecdfbc6217ee1b9ae5093bf5a7d72e7d06ac4
Showing with 47 additions and 45 deletions.
  1. +47 −1 { → optional}/rails-ruby.el
  2. +0 −44 rails.el
@@ -29,6 +29,16 @@
;; setup align for ruby-mode
(require 'align)
+(defcustom rails-indent-and-complete t
+ "Key to indent and complete."
+ :group 'rails
+ :type 'boolean)
+
+(defcustom rails-enable-ruby-electric t
+ "Indicates whether ruby electric minor mode should be enabled by default for ruby files"
+ :group 'rails
+ :type 'boolean)
+
(defconst align-ruby-modes '(ruby-mode)
"align-perl-modes is a variable defined in `align.el'.")
@@ -208,5 +218,41 @@ See the variable `align-rules-list' for more details.")
(cmd (if maxnum (concat cmd (format "[0...%s]" maxnum)) cmd)))
(el4r-ruby-eval (format cmd (word-at-point) prefix prefix)))))))
+(defun backward-ruby-object ()
+ (if (looking-back "[-a-zA-Z_#:*]+" (line-beginning-position) t)
+ (goto-char (match-beginning 0))))
-(provide 'rails-ruby)
+(defun forward-ruby-object (n)
+ (if (> 0 n)
+ (when (search-backward-regexp "[^-a-zA-Z_#:*][-a-zA-Z_#:*]+" nil t (- n))
+ (forward-char)
+ (point))
+ (when (search-forward-regexp "[-a-zA-Z_#:*]+" nil t n)
+ (goto-char (match-end 0)))))
+
+(add-hook 'ruby-mode-hook
+ (lambda ()
+ (when (rails-project:root)
+ (require 'rails-ruby)
+ (require 'ruby-electric)
+ (ruby-electric-mode (or rails-enable-ruby-electric -1))
+ (ruby-hs-minor-mode t)
+ (imenu-add-to-menubar "IMENU")
+ (if rails-indent-and-complete
+ (local-set-key (if rails-use-another-define-key
+ (kbd "TAB") (kbd "<tab>"))
+ 'indent-and-complete))
+ (local-set-key (kbd "C-:") 'ruby-toggle-string<>simbol)
+ (local-set-key (if rails-use-another-define-key
+ (kbd "RET") (kbd "<return>"))
+ 'ruby-newline-and-indent))))
+
+
+
+(add-hook 'find-file-hooks
+ (if rails-indent-and-complete
+ (local-set-key (if rails-use-another-define-key
+ (kbd "TAB") (kbd "<tab>"))
+ 'indent-and-complete)))
+
+(provide 'rails-ruby)
View
@@ -63,7 +63,6 @@
;;;;;;;;; Loading most of the mode
(require 'rails-core)
-(require 'rails-ruby)
(require 'rails-lib)
(require 'rails-cmd-proxy)
@@ -158,11 +157,6 @@ Emacs w3m browser."
:group 'rails
:type 'string)
-(defcustom rails-enable-ruby-electric t
- "Indicates whether ruby electric minor mode should be enabled by default for ruby files"
- :group 'rails
- :type 'boolean)
-
(defcustom rails-number-of-lines-shown-when-opening-log-file 130
"Specifies how many lines to show initially when opening a log file"
:group 'rails
@@ -174,11 +168,6 @@ Emacs w3m browser."
(defvar rails-secondary-switch-func nil)
(defvar rails-required-lisp-eval-depth 1000) ; Specifies the minimum required value of max-lisp-eval-depth for rails mode to work
-(defcustom rails-indent-and-complete t
- "Key to indent and complete."
- :group 'rails
- :type 'boolean)
-
(defvar rails-directory<-->types
'((:controller "app/controllers/")
(:layout "app/views/layouts/")
@@ -275,18 +264,6 @@ Emacs w3m browser."
;; helper functions/macros
-(defun backward-ruby-object ()
- (if (looking-back "[-a-zA-Z_#:*]+" (line-beginning-position) t)
- (goto-char (match-beginning 0))))
-
-(defun forward-ruby-object (n)
- (if (> 0 n)
- (when (search-backward-regexp "[^-a-zA-Z_#:*][-a-zA-Z_#:*]+" nil t (- n))
- (forward-char)
- (point))
- (when (search-forward-regexp "[-a-zA-Z_#:*]+" nil t n)
- (goto-char (match-end 0)))))
-
(defun rails-search-doc (&optional item)
(interactive)
(setq item (if item item (thing-at-point 'ruby-object)))
@@ -503,23 +480,6 @@ necessary."
;; hooks
-(add-hook 'ruby-mode-hook
- (lambda ()
- (when (rails-project:root)
- (require 'rails-ruby)
- (require 'ruby-electric)
- (ruby-electric-mode (or rails-enable-ruby-electric -1))
- (ruby-hs-minor-mode t)
- (imenu-add-to-menubar "IMENU")
- (if rails-indent-and-complete
- (local-set-key (if rails-use-another-define-key
- (kbd "TAB") (kbd "<tab>"))
- 'indent-and-complete))
- (local-set-key (kbd "C-:") 'ruby-toggle-string<>simbol)
- (local-set-key (if rails-use-another-define-key
- (kbd "RET") (kbd "<return>"))
- 'ruby-newline-and-indent))))
-
(add-hook 'speedbar-mode-hook
(lambda()
(speedbar-add-supported-extension "\\.rb")))
@@ -529,10 +489,6 @@ necessary."
(rails-project:with-root
(root)
(progn
- (if rails-indent-and-complete
- (local-set-key (if rails-use-another-define-key
- (kbd "TAB") (kbd "<tab>"))
- 'indent-and-complete))
(rails-minor-mode t)
(rails-apply-for-buffer-type)))))

0 comments on commit fddecdf

Please sign in to comment.