Skip to content

Commit

Permalink
Factor out ruby flymake functions so it's easier to disable.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Jun 23, 2010
1 parent fd24e10 commit d15b7ca
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions starter-kit-ruby.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
(pcomplete-here (pcmpl-rake-tasks)))

(defun pcmpl-rake-tasks ()
"Return a list of all the rake tasks defined in the current
"Return a list of all the rake tasks defined in the current
projects. I know this is a hack to put all the logic in the
exec-to-string command, but it works and seems fast"
(delq nil (mapcar '(lambda(line)
(if (string-match "rake \\([^ ]+\\)" line) (match-string 1 line)))
(split-string (shell-command-to-string "rake -T") "[\n]"))))
(delq nil (mapcar '(lambda(line)
(if (string-match "rake \\([^ ]+\\)" line) (match-string 1 line)))
(split-string (shell-command-to-string "rake -T") "[\n]"))))

(defun rake (task)
(interactive (list (completing-read "Rake (default: default): "
Expand All @@ -60,44 +60,42 @@ exec-to-string command, but it works and seems fast"

;;; Flymake

(defun flymake-ruby-init ()
(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))))
;; Invoke ruby with '-c' to get syntax checking
(list "ruby" (list "-c" local-file))))

(defun flymake-ruby-enable ()
(when (and buffer-file-name
(file-writable-p
(file-name-directory buffer-file-name))
(file-writable-p buffer-file-name)
(if (fboundp 'tramp-list-remote-buffers)
(not (subsetp
(list (current-buffer))
(tramp-list-remote-buffers)))
t))
(local-set-key (kbd "C-c d")
'flymake-display-err-menu-for-current-line)
(flymake-mode t)))

(eval-after-load 'ruby-mode
'(progn
(require 'flymake)

;; Invoke ruby with '-c' to get syntax checking
(defun flymake-ruby-init ()
(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 "ruby" (list "-c" local-file))))

(push '(".+\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks)

(push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3)
flymake-err-line-patterns)

(add-hook 'ruby-mode-hook
(lambda ()
(when (and buffer-file-name
(file-writable-p
(file-name-directory buffer-file-name))
(file-writable-p buffer-file-name)
(if (fboundp 'tramp-list-remote-buffers)
(not (subsetp
(list (current-buffer))
(tramp-list-remote-buffers)))
t))
(local-set-key (kbd "C-c d")
'flymake-display-err-menu-for-current-line)
(flymake-mode t))))))
(add-hook 'ruby-mode-hook 'flymake-ruby-enable)))

;; Rinari (Minor Mode for Ruby On Rails)
(setq rinari-major-modes
(list 'mumamo-after-change-major-mode-hook 'dired-mode-hook 'ruby-mode-hook
'css-mode-hook 'yaml-mode-hook 'javascript-mode-hook))
'css-mode-hook 'yaml-mode-hook 'javascript-mode-hook))

;; TODO: set up ri
;; TODO: electric
Expand Down

0 comments on commit d15b7ca

Please sign in to comment.