forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-ruby-mode.el
104 lines (76 loc) · 3.67 KB
/
init-ruby-mode.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(require-package 'ruby-mode)
(require-package 'flymake-ruby)
(require-package 'rinari)
(require-package 'ruby-compilation)
(require-package 'inf-ruby)
(require-package 'robe)
(require-package 'yari)
(require-package 'yaml-mode)
(require-package 'haml-mode)
(require-package 'mmm-mode)
(eval-after-load 'rinari
'(diminish 'rinari-minor-mode "Rin"))
(add-auto-mode 'ruby-mode
"Rakefile\\'" "\.rake\\'" "\.rxml\\'"
"\.rjs\\'" ".irbrc\\'" "\.builder\\'" "\.ru\\'"
"\.gemspec\\'" "Gemfile\\'" "Kirkfile\\'")
(autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process")
(setq ruby-use-encoding-map nil)
(eval-after-load 'ruby-mode
'(progn
(define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
(define-key ruby-mode-map (kbd "TAB") 'indent-for-tab-command)))
;;----------------------------------------------------------------------------
;; Ruby - flymake
;;----------------------------------------------------------------------------
(add-hook 'ruby-mode-hook 'flymake-ruby-load)
;;----------------------------------------------------------------------------
;; Ruby - robe
;;----------------------------------------------------------------------------
(add-hook 'ruby-mode-hook 'robe-mode)
(add-hook 'robe-mode-hook
(lambda ()
(add-to-list 'ac-sources 'ac-source-robe)
(setq completion-at-point-functions '(auto-complete))))
;;----------------------------------------------------------------------------
;; Ruby - misc
;;----------------------------------------------------------------------------
(defalias 'ri 'yari)
;;----------------------------------------------------------------------------
;; Ruby - erb
;;----------------------------------------------------------------------------
(defun sanityinc/ensure-mmm-erb-loaded ()
(require 'mmm-erb))
(dolist (hook (list 'html-mode-hook 'nxml-mode-hook 'yaml-mode-hook))
(add-hook hook 'sanityinc/ensure-mmm-erb-loaded))
(dolist (mode (list 'html-mode 'html-erb-mode 'nxml-mode))
(mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-js)
(mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-css)
(mmm-add-mode-ext-class mode "\\.erb\\'" 'erb))
(require-package 'tagedit)
(eval-after-load "sgml-mode"
'(progn
(tagedit-add-paredit-like-keybindings)))
(mmm-add-mode-ext-class 'html-erb-mode "\\.jst\\.ejs\\'" 'ejs)
(add-auto-mode 'html-erb-mode "\\.rhtml\\'" "\\.html\\.erb\\'")
(add-to-list 'auto-mode-alist '("\\.jst\\.ejs\\'" . html-erb-mode))
(mmm-add-mode-ext-class 'yaml-mode "\\.yaml\\'" 'erb)
(dolist (mode (list 'js-mode 'js2-mode 'js3-mode))
(mmm-add-mode-ext-class mode "\\.js\\.erb\\'" 'erb))
;;----------------------------------------------------------------------------
;; Ruby - my convention for heredocs containing SQL
;;----------------------------------------------------------------------------
;; (eval-after-load 'mmm-mode
;; '(progn
;; (mmm-add-classes
;; '((ruby-heredoc-sql :submode sql-mode :front "<<-?end_sql.*\r?\n" :back "[ \t]*end_sql" :face mmm-code-submode-face)))
;; (mmm-add-mode-ext-class 'ruby-mode "\\.rb\\'" 'ruby-heredoc-sql)))
;;----------------------------------------------------------------------------
;; Ruby - compilation
;;----------------------------------------------------------------------------
; run the current buffer using Shift-F7
(add-hook 'ruby-mode-hook (lambda () (local-set-key [S-f7] 'ruby-compilation-this-buffer)))
; run the current test function using F8 key
(add-hook 'ruby-mode-hook (lambda () (local-set-key [f7] 'ruby-compilation-this-test)))
(add-hook 'ruby-mode-hook (lambda () (local-set-key [f6] 'recompile)))
(provide 'init-ruby-mode)