diff --git a/ChangeLog b/ChangeLog index 80ccfe7..3a4f65a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-08-15 Dmitry Galinsky + + * rails-ruby.el (ruby-hs-minor-mode): created, support ruby in hs-minor-mode + 2007-08-11 Dmitry Galinsky * rails-compat.el (try-complete-abbrev): fixed diff --git a/History b/History index 67a0615..bef5fbb 100644 --- a/History +++ b/History @@ -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. diff --git a/rails-features.el b/rails-features.el index 14c4d1a..4a5427b 100644 --- a/rails-features.el +++ b/rails-features.el @@ -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) diff --git a/rails-ruby.el b/rails-ruby.el index a927f1b..ee70c23 100644 --- a/rails-ruby.el +++ b/rails-ruby.el @@ -26,8 +26,6 @@ ;;; Code: -(require 'inf-ruby) - ;; setup align for ruby-mode (require 'align) @@ -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 () @@ -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 "*"))) @@ -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) \ No newline at end of file diff --git a/rails.el b/rails.el index 950d42c..5348578 100644 --- a/rails.el +++ b/rails.el @@ -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))