forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-ruby-mode.el
132 lines (91 loc) · 3.72 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
;;; Basic ruby setup
(require-package 'ruby-mode)
(require-package 'ruby-hash-syntax)
(add-auto-mode 'ruby-mode
"Rakefile\\'" "\\.rake\\'" "\\.rxml\\'"
"\\.rjs\\'" "\\.irbrc\\'" "\\.pryrc\\'" "\\.builder\\'" "\\.ru\\'"
"\\.gemspec\\'" "Gemfile\\'" "Kirkfile\\'")
(setq ruby-use-encoding-map nil)
(after-load 'ruby-mode
(define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
(define-key ruby-mode-map (kbd "TAB") 'indent-for-tab-command)
;; Stupidly the non-bundled ruby-mode isn't a derived mode of
;; prog-mode: we run the latter's hooks anyway in that case.
(add-hook 'ruby-mode-hook
(lambda ()
(unless (derived-mode-p 'prog-mode)
(run-hooks 'prog-mode-hook)))))
(add-hook 'ruby-mode-hook 'subword-mode)
;; TODO: hippie-expand ignoring : for names in ruby-mode
;; TODO: hippie-expand adaptor for auto-complete sources
;;; Inferior ruby
(require-package 'inf-ruby)
(require-package 'ac-inf-ruby)
(after-load 'auto-complete
(add-to-list 'ac-modes 'inf-ruby-mode))
(add-hook 'inf-ruby-mode-hook 'ac-inf-ruby-enable)
(after-load 'inf-ruby
(define-key inf-ruby-mode-map (kbd "TAB") 'auto-complete))
;;; Ruby compilation
(require-package 'ruby-compilation)
(after-load 'ruby-mode
(let ((m ruby-mode-map))
(define-key m [S-f7] 'ruby-compilation-this-buffer)
(define-key m [f7] 'ruby-compilation-this-test)
(define-key m [f6] 'recompile)))
;;; Robe
(require-package 'robe)
(after-load 'ruby-mode
(add-hook 'ruby-mode-hook 'robe-mode))
(after-load 'robe
(add-hook 'robe-mode-hook
(lambda ()
(add-to-list 'ac-sources 'ac-source-robe)
(set-auto-complete-as-completion-at-point-function))))
;;; ri support
(require-package 'yari)
(defalias 'ri 'yari)
;;; YAML
(require-package 'yaml-mode)
;;; ERB
(require-package 'mmm-mode)
(defun sanityinc/ensure-mmm-erb-loaded ()
(require 'mmm-erb))
(require 'derived)
(defun sanityinc/set-up-mode-for-erb (mode)
(add-hook (derived-mode-hook-name mode) 'sanityinc/ensure-mmm-erb-loaded)
(mmm-add-mode-ext-class mode "\\.erb\\'" 'erb))
(let ((html-erb-modes '(html-mode html-erb-mode nxml-mode)))
(dolist (mode html-erb-modes)
(sanityinc/set-up-mode-for-erb mode)
(mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-js)
(mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-css)))
(mapc 'sanityinc/set-up-mode-for-erb
'(coffee-mode js-mode js2-mode js3-mode markdown-mode textile-mode))
(require-package 'tagedit)
(after-load 'sgml-mode
(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
;;----------------------------------------------------------------------------
;; Needs to run after rinari to avoid clobbering font-lock-keywords?
;; (require-package 'mmm-mode)
;; (eval-after-load 'mmm-mode
;; '(progn
;; (mmm-add-classes
;; '((ruby-heredoc-sql
;; :submode sql-mode
;; :front "<<-?[\'\"]?\\(end_sql\\)[\'\"]?"
;; :save-matches 1
;; :front-offset (end-of-line 1)
;; :back "^[ \t]*~1$"
;; :delimiter-mode nil)))
;; (mmm-add-mode-ext-class 'ruby-mode "\\.rb\\'" 'ruby-heredoc-sql)))
;(add-to-list 'mmm-set-file-name-for-modes 'ruby-mode)
(provide 'init-ruby-mode)