-
Notifications
You must be signed in to change notification settings - Fork 2
/
init-ruby.el
136 lines (105 loc) · 4.83 KB
/
init-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
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
133
134
135
136
;;; init-ruby.el --- Some helpful Ruby code
(defun ruby-eval-buffer () (interactive)
"Evaluate the buffer with ruby."
(shell-command-on-region (point-min) (point-max) "ruby"))
(eval-after-load 'ruby-mode
'(progn
(require 'ruby-compilation)
(setq ruby-use-encoding-map nil)
(add-hook 'ruby-mode-hook
(lambda ()
(inf-ruby-keys)
(ruby-electric-mode t)))
;(set (make-local-variable 'indent-tabs-mode) 'nil)
;(set (make-local-variable 'tab-width) 2)
(define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
(define-key ruby-mode-map (kbd "C-j") 'newline)
(define-key ruby-mode-map (kbd "C-M-h") 'backward-kill-word)
(define-key ruby-mode-map (kbd "C-c l") "lambda")
(define-key ruby-mode-map (kbd "C-c v") 'ruby-eval-buffer)))
(global-set-key (kbd "C-h r") 'ri)
;; Rake files are ruby, too, as are gemspecs.
(add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.sake$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.gemspec$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.ya?ml$" . yaml-mode))
;; We never want to edit Rubinius bytecode
(add-to-list 'completion-ignored-extensions ".rbc")
;;; Rake
(defun pcomplete/rake ()
"Completion rules for the `rake' command."
(pcomplete-here (pcmpl-rake-tasks)))
(defun pcmpl-rake-tasks ()
"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]"))))
(defun rake (task)
(interactive (list (completing-read "Rake (default: default): "
(pcmpl-rake-tasks))))
(shell-command-to-string (concat "rake " (if (= 0 (length task)) "default" task))))
;; Clear the compilation buffer between test runs.
(eval-after-load 'ruby-compilation
'(progn
(defadvice ruby-do-run-w/compilation (before kill-buffer (name cmdlist))
(let ((comp-buffer-name (format "*%s*" name)))
(when (get-buffer comp-buffer-name)
(with-current-buffer comp-buffer-name
(delete-region (point-min) (point-max))))))
(ad-activate 'ruby-do-run-w/compilation)))
(add-hook 'ruby-mode-hook 'coding-hook)
;;; 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" 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))
(local-set-key (kbd "C-c d")
'flymake-display-err-menu-for-current-line)
(flymake-mode t))))))
;;; ri
;; (setq ri-ruby-script (expand-file-name "~/.emacs.d/vendor/ri-emacs/ri-emacs.rb"))
;; (autoload 'ri (expand-file-name "~/.emacs.d/vendor/ri-emacs/ri-ruby.el") nil t)
;; (add-hook 'ruby-mode-hook
;; (lambda ()
;; (local-set-key [f1] 'ri)
;; (local-set-key [f4] 'ri-ruby-show-args)
;; (local-set-key (kbd "M-C-i") 'ri-ruby-complete-symbol)))
;; Rinari
;; (require 'rinari)
;; HAML and SASS
(autoload 'haml-mode "haml-mode.el"
"Major mode for editing HAML files" t)
(add-to-list 'auto-mode-alist '("\\.haml$" . haml-mode))
;(define-key haml-mode-map [(control meta down)] 'haml-forward-sexp)
;(define-key haml-mode-map [(control meta up)] 'haml-backward-sexp)
;(define-key haml-mode-map [(control meta left)] 'haml-up-list)
;(define-key haml-mode-map [(control meta right)] 'haml-down-list)
(autoload 'sass-mode "sass-mode.el"
"Major mode for editing SASS files" t)
(add-to-list 'auto-mode-alist '("\\.sass$" . sass-mode))
(eval-after-load 'haml-mode
(if (functionp 'whitespace-mode)
(add-hook 'haml-mode-hook 'whitespace-mode)))
(provide 'init-ruby)
;; init-ruby.el ends here