Permalink
Browse files

Streamline and document code

  • Loading branch information...
purcell committed Oct 13, 2011
1 parent 0de1efa commit 6afcd87728ee00450a7ac0709e5e972438ed6c10
Showing with 19 additions and 14 deletions.
  1. +19 −14 flymake-ruby.el
View
@@ -2,33 +2,38 @@
;;
;;; Author: Steve Purcell <steve@sanityinc.com>
;;; URL: https://github.com/purcell/flymake-ruby
-;;; Version: 0.1
+;;; Version: DEV
;;;
-;;; Commentary
+;;; Commentary:
;; Usage:
;; (require 'flymake-ruby)
;; (add-hook 'ruby-mode-hook 'flymake-ruby-load)
-(defvar flymake-ruby-err-line-patterns '(("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3)))
-(defvar flymake-ruby-allowed-file-name-masks '((".+\\.\\(rb\\|rake\\)$" flymake-ruby-init)
- ("Rakefile$" flymake-ruby-init)))
+(defconst flymake-ruby-err-line-patterns '(("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3)))
-;; Not provided by flymake itself, curiously
-(defun flymake-create-temp-in-system-tempdir (filename prefix)
- (make-temp-file (or prefix "flymake-ruby")))
+(defvar flymake-ruby-executable "ruby"
+ "The ruby executable to use for syntax checking")
;; Invoke ruby with '-c' to get syntax checking
(defun flymake-ruby-init ()
- (list "ruby" (list "-c" (flymake-init-create-temp-buffer-copy
- 'flymake-create-temp-in-system-tempdir))))
+ (list flymake-ruby-executable
+ (list "-c" (flymake-init-create-temp-buffer-copy
+ 'flymake-create-temp-inplace))))
+;;;###autoload
(defun flymake-ruby-load ()
+ "Configure flymake mode to check the current buffer's ruby syntax.
+
+This function is designed to be called in `ruby-mode-hook'; it
+does not alter flymake's global configuration, so `flymake-mode'
+alone will not suffice."
(interactive)
- (unless (eq buffer-file-name nil)
- (set (make-local-variable 'flymake-allowed-file-name-masks) flymake-ruby-allowed-file-name-masks)
- (set (make-local-variable 'flymake-err-line-patterns) flymake-ruby-err-line-patterns)
- (flymake-mode t)))
+ (set (make-local-variable 'flymake-allowed-file-name-masks) '(("." flymake-ruby-init)))
+ (set (make-local-variable 'flymake-err-line-patterns) flymake-ruby-err-line-patterns)
+ (if (executable-find flymake-ruby-executable)
+ (flymake-mode t)
+ (message "Not enabling flymake: '%' command not found" flymake-ruby-executable)))
(provide 'flymake-ruby)

0 comments on commit 6afcd87

Please sign in to comment.