Skip to content

Commit

Permalink
rails-ruby.el (ruby-hs-minor-mode): created, support ruby in hs-minor…
Browse files Browse the repository at this point in the history
…-mode

git-svn-id: svn+ssh://rubyforge.org/var/svn/emacs-rails/trunk@207 cc5033d0-740f-0410-afc7-949910e492f2
  • Loading branch information
dimaexe committed Aug 15, 2007
1 parent 154f696 commit 62757ee
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 45 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2007-08-15 Dmitry Galinsky <[email protected]>

* rails-ruby.el (ruby-hs-minor-mode): created, support ruby in hs-minor-mode

2007-08-11 Dmitry Galinsky <[email protected]>

* rails-compat.el (try-complete-abbrev): fixed
Expand Down
1 change: 1 addition & 0 deletions History
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SVN
* Added ruby-mode support in hs-minor-mode (aka folding).
* Added migrations and configuration files to speedbar.
* More shortcuts for tests.

Expand Down
3 changes: 2 additions & 1 deletion rails-features.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

(defvar rails-features:list
'(rails-snippets-feature
rails-speedbar-feature)
rails-speedbar-feature
rails-rspec-feature)
"List of features")

(defvar rails-features:installed-p nil)
Expand Down
117 changes: 73 additions & 44 deletions rails-ruby.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

;;; Code:

(require 'inf-ruby)

;; setup align for ruby-mode
(require 'align)

Expand Down Expand Up @@ -56,6 +54,77 @@ See the variable `align-rules-list' for more details.")
(dolist (it ruby-align-rules-list)
(add-to-list 'align-rules-list it))

;; hideshow ruby support

(defun display-code-line-counts (ov)
(when (eq 'code (overlay-get ov 'hs))
(overlay-put ov 'face 'font-lock-comment-face)
(overlay-put ov 'display
(format " »»» %d lines"
(count-lines (overlay-start ov)
(overlay-end ov))))))

(defun ruby-hs-minor-mode (&optional arg)
(interactive)
(require 'hideshow)
(unless (assoc 'ruby-mode hs-special-modes-alist)
(setq
hs-special-modes-alist
(cons (list 'ruby-mode
"\\(def\\|do\\)"
"end"
"#"
(lambda (&rest args) (ruby-end-of-block))
;(lambda (&rest args) (ruby-beginning-of-defun))
)
hs-special-modes-alist)))
(unless hs-set-up-overlay
(setq hs-set-up-overlay 'display-code-line-counts))
(hs-minor-mode arg))

;; flymake ruby support

(require 'flymake nil t)

(defconst flymake-allowed-ruby-file-name-masks
'(("\\.rb\\'" flymake-ruby-init)
("\\.rxml\\'" flymake-ruby-init)
("\\.builder\\'" flymake-ruby-init)
("\\.rjs\\'" flymake-ruby-init))
"Filename extensions that switch on flymake-ruby mode syntax checks.")

(defconst flymake-ruby-error-line-pattern-regexp
'("^\\([^:]+\\):\\([0-9]+\\): *\\([\n]+\\)" 1 2 nil 3)
"Regexp matching ruby error messages.")

(defun flymake-ruby-init ()
(condition-case er
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list rails-ruby-command (list "-c" local-file)))
('error ())))

(defun flymake-ruby-load ()
(when (and (buffer-file-name)
(string-match
(format "\\(%s\\)"
(string-join
"\\|"
(mapcar 'car flymake-allowed-ruby-file-name-masks)))
(buffer-file-name)))
(setq flymake-allowed-file-name-masks
(append flymake-allowed-file-name-masks flymake-allowed-ruby-file-name-masks))
(setq flymake-err-line-patterns
(cons flymake-ruby-error-line-pattern-regexp flymake-err-line-patterns))
(flymake-mode t)
(local-set-key (rails-key "d") 'flymake-display-err-menu-for-current-line)))

(when (featurep 'flymake)
(add-hook 'ruby-mode-hook 'flymake-ruby-load))

;; other stuff

(defun ruby-newline-and-indent ()
Expand Down Expand Up @@ -95,6 +164,8 @@ See the variable `align-rules-list' for more details.")
(insert (format "'%s'" symbol-str))))))
(goto-char initial-pos)))

(require 'inf-ruby)

(defun run-ruby-in-buffer (cmd buf)
"Run CMD as a ruby process in BUF if BUF does not exist."
(let ((abuf (concat "*" buf "*")))
Expand All @@ -121,47 +192,5 @@ 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)))))))

;; flymake ruby support

(require 'flymake nil t)

(defconst flymake-allowed-ruby-file-name-masks
'(("\\.rb\\'" flymake-ruby-init)
("\\.rxml\\'" flymake-ruby-init)
("\\.builder\\'" flymake-ruby-init)
("\\.rjs\\'" flymake-ruby-init))
"Filename extensions that switch on flymake-ruby mode syntax checks.")

(defconst flymake-ruby-error-line-pattern-regexp
'("^\\([^:]+\\):\\([0-9]+\\): *\\([\n]+\\)" 1 2 nil 3)
"Regexp matching ruby error messages.")

(defun flymake-ruby-init ()
(condition-case er
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list rails-ruby-command (list "-c" local-file)))
('error ())))

(defun flymake-ruby-load ()
(when (and (buffer-file-name)
(string-match
(format "\\(%s\\)"
(string-join
"\\|"
(mapcar 'car flymake-allowed-ruby-file-name-masks)))
(buffer-file-name)))
(setq flymake-allowed-file-name-masks
(append flymake-allowed-file-name-masks flymake-allowed-ruby-file-name-masks))
(setq flymake-err-line-patterns
(cons flymake-ruby-error-line-pattern-regexp flymake-err-line-patterns))
(flymake-mode t)
(local-set-key (rails-key "d") 'flymake-display-err-menu-for-current-line)))

(when (featurep 'flymake)
(add-hook 'ruby-mode-hook 'flymake-ruby-load))

(provide 'rails-ruby)
1 change: 1 addition & 0 deletions rails.el
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ necessary."
(require 'rails-ruby)
(require 'ruby-electric)
(ruby-electric-mode t)
(ruby-hs-minor-mode t)
(imenu-add-to-menubar "IMENU")
(modify-syntax-entry ?! "w" (syntax-table))
(modify-syntax-entry ?: "w" (syntax-table))
Expand Down

0 comments on commit 62757ee

Please sign in to comment.