Created
December 9, 2008 16:25
-
-
Save rwc9u/33954 to your computer and use it in GitHub Desktop.
ruby flymake support
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
;;============================================================ | |
;; flymake | |
;;============================================================ | |
;; flymake ruby support | |
;; thanks to Dmitry Galinsky - this was taken from emacs-rails | |
(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 "/opt/local/bin/ruby" (list "-c" local-file))) | |
('error ()))) | |
;; TODO - pull these out to my rwc-defuns file. | |
(defun strings-join (separator strings) | |
"Join all STRINGS using a SEPARATOR." | |
(mapconcat 'identity strings separator)) | |
(defalias 'string-join 'strings-join) | |
(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 (kbd "\C-c d") 'flymake-display-err-menu-for-current-line))) | |
(when (featurep 'flymake) | |
(add-hook 'ruby-mode-hook 'flymake-ruby-load)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment