-
Notifications
You must be signed in to change notification settings - Fork 5
/
rc-ruby.el
79 lines (74 loc) · 3.4 KB
/
rc-ruby.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(eval-after-load 'ruby-mode
'(progn
(define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)))
(add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.gemspec$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rjs$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.ru$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Gemfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Capfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Guardfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("/\\.\\(irb\\|cap\\)rc$" . ruby-mode))
(defadvice ruby-indent-line (after line-up-args activate)
(let (indent prev-indent arg-indent)
(save-excursion
(back-to-indentation)
(when (zerop (car (syntax-ppss)))
(setq indent (current-column))
(skip-chars-backward " \t\n")
(when (eq ?, (char-before))
(ruby-backward-sexp)
(back-to-indentation)
(setq prev-indent (current-column))
(skip-syntax-forward "w_.")
(skip-chars-forward " ")
(setq arg-indent (current-column)))))
(when prev-indent
(let ((offset (- (current-column) indent)))
(cond ((< indent prev-indent)
(indent-line-to prev-indent))
((= indent prev-indent)
(indent-line-to arg-indent)))
(when (> offset 0) (forward-char offset))))))
(add-hook 'ruby-mode-hook
(lambda ()
(make-local-variable 'ac-ignores)
(add-to-list 'ac-ignores "end")))
;; flymake
(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" "-W2" local-file))))
(push '("\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("\\.rake$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("\\.gemspec$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("\\.ru$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("Gemfile$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("Capfile$" 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))))))
;; rvm
(rvm-autodetect-ruby)