Skip to content
Newer
Older
100644 105 lines (86 sloc) 3.83 KB
5fcb34d @technomancy initial commit
technomancy authored
1 ;;; starter-kit-ruby.el --- Some helpful Ruby code
2 ;;
3 ;; Part of the Emacs Starter Kit
4
12ac2f0 @technomancy Rearrange lisp and ruby helpers.
technomancy authored
5 (eval-after-load 'ruby-mode
6 '(progn
ad5705f @technomancy Instructions for how to work around ELPA upgrade problems.
technomancy authored
7 ;; work around possible elpa bug
8 (ignore-errors (require 'ruby-compilation))
b95c632 @technomancy Doc updates, textile-mode, and a haml fix.
technomancy authored
9 (setq ruby-use-encoding-map nil)
680a6d6 @technomancy ruby-compilation cleanups.
technomancy authored
10 (add-hook 'ruby-mode-hook 'inf-ruby-keys)
f821261 @technomancy Autoload and invoke paredit. Fix ruby-mode RET.
technomancy authored
11 (define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
1f6f58b @technomancy Extracted cleanup buffer function.
technomancy authored
12 (define-key ruby-mode-map (kbd "C-M-h") 'backward-kill-word)
12ac2f0 @technomancy Rearrange lisp and ruby helpers.
technomancy authored
13 (define-key ruby-mode-map (kbd "C-c l") "lambda")))
5fcb34d @technomancy initial commit
technomancy authored
14
15 (global-set-key (kbd "C-h r") 'ri)
16
ada2ac9 @smerritt Use ruby-mode for Capfile
smerritt authored
17 ;; Rake files are ruby, too, as are gemspecs, rackup files, etc.
b4aa114 @technomancy Added some rake functions.
technomancy authored
18 (add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
9eedd2e @technomancy Gemspecs are ruby code.
technomancy authored
19 (add-to-list 'auto-mode-alist '("\\.gemspec$" . ruby-mode))
d7439fe @smerritt Use ruby-mode for Gemfile and rackup files
smerritt authored
20 (add-to-list 'auto-mode-alist '("\\.ru$" . ruby-mode))
6b38e16 @technomancy Use ruby-mode for Vagrantfile.
technomancy authored
21 (add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
d7439fe @smerritt Use ruby-mode for Gemfile and rackup files
smerritt authored
22 (add-to-list 'auto-mode-alist '("Gemfile$" . ruby-mode))
ada2ac9 @smerritt Use ruby-mode for Capfile
smerritt authored
23 (add-to-list 'auto-mode-alist '("Capfile$" . ruby-mode))
6b38e16 @technomancy Use ruby-mode for Vagrantfile.
technomancy authored
24 (add-to-list 'auto-mode-alist '("Vagrantfile$" . ruby-mode))
b4aa114 @technomancy Added some rake functions.
technomancy authored
25
5fcb34d @technomancy initial commit
technomancy authored
26 ;; We never want to edit Rubinius bytecode
27 (add-to-list 'completion-ignored-extensions ".rbc")
28
b4aa114 @technomancy Added some rake functions.
technomancy authored
29 ;;; Rake
30
31 (defun pcomplete/rake ()
32 "Completion rules for the `ssh' command."
33 (pcomplete-here (pcmpl-rake-tasks)))
34
35 (defun pcmpl-rake-tasks ()
d15b7ca @technomancy Factor out ruby flymake functions so it's easier to disable.
technomancy authored
36 "Return a list of all the rake tasks defined in the current
b4aa114 @technomancy Added some rake functions.
technomancy authored
37 projects. I know this is a hack to put all the logic in the
38 exec-to-string command, but it works and seems fast"
d15b7ca @technomancy Factor out ruby flymake functions so it's easier to disable.
technomancy authored
39 (delq nil (mapcar '(lambda(line)
40 (if (string-match "rake \\([^ ]+\\)" line) (match-string 1 line)))
41 (split-string (shell-command-to-string "rake -T") "[\n]"))))
b4aa114 @technomancy Added some rake functions.
technomancy authored
42
43 (defun rake (task)
44 (interactive (list (completing-read "Rake (default: default): "
45 (pcmpl-rake-tasks))))
46 (shell-command-to-string (concat "rake " (if (= 0 (length task)) "default" task))))
47
48
838e8f9 @technomancy Clear compilation buffer in between test runs.
technomancy authored
49 ;; Clear the compilation buffer between test runs.
50 (eval-after-load 'ruby-compilation
51 '(progn
52 (defadvice ruby-do-run-w/compilation (before kill-buffer (name cmdlist))
53 (let ((comp-buffer-name (format "*%s*" name)))
54 (when (get-buffer comp-buffer-name)
55 (with-current-buffer comp-buffer-name
56 (delete-region (point-min) (point-max))))))
57 (ad-activate 'ruby-do-run-w/compilation)))
58
b2ffdf1 @technomancy Make coding-hook a real hook instead of a defun.
technomancy authored
59 (add-hook 'ruby-mode-hook 'run-coding-hook)
38ac75b @technomancy Remove cheat binding, use coding-hook.
technomancy authored
60
eb4d3d5 @technomancy Set up flymake for ruby files.
technomancy authored
61 ;;; Flymake
62
d15b7ca @technomancy Factor out ruby flymake functions so it's easier to disable.
technomancy authored
63 (defun flymake-ruby-init ()
64 (let* ((temp-file (flymake-init-create-temp-buffer-copy
65 'flymake-create-temp-inplace))
66 (local-file (file-relative-name
67 temp-file
68 (file-name-directory buffer-file-name))))
69 ;; Invoke ruby with '-c' to get syntax checking
70 (list "ruby" (list "-c" local-file))))
71
72 (defun flymake-ruby-enable ()
73 (when (and buffer-file-name
74 (file-writable-p
75 (file-name-directory buffer-file-name))
76 (file-writable-p buffer-file-name)
77 (if (fboundp 'tramp-list-remote-buffers)
78 (not (subsetp
79 (list (current-buffer))
80 (tramp-list-remote-buffers)))
81 t))
82 (local-set-key (kbd "C-c d")
83 'flymake-display-err-menu-for-current-line)
84 (flymake-mode t)))
85
eb4d3d5 @technomancy Set up flymake for ruby files.
technomancy authored
86 (eval-after-load 'ruby-mode
87 '(progn
88 (require 'flymake)
89 (push '(".+\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks)
90 (push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks)
91 (push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3)
92 flymake-err-line-patterns)
d15b7ca @technomancy Factor out ruby flymake functions so it's easier to disable.
technomancy authored
93 (add-hook 'ruby-mode-hook 'flymake-ruby-enable)))
eb4d3d5 @technomancy Set up flymake for ruby files.
technomancy authored
94
6293b8d @eschulte Rinari working in starter-kit.el
eschulte authored
95 ;; Rinari (Minor Mode for Ruby On Rails)
96 (setq rinari-major-modes
97 (list 'mumamo-after-change-major-mode-hook 'dired-mode-hook 'ruby-mode-hook
d15b7ca @technomancy Factor out ruby flymake functions so it's easier to disable.
technomancy authored
98 'css-mode-hook 'yaml-mode-hook 'javascript-mode-hook))
6293b8d @eschulte Rinari working in starter-kit.el
eschulte authored
99
5fcb34d @technomancy initial commit
technomancy authored
100 ;; TODO: set up ri
101 ;; TODO: electric
102
103 (provide 'starter-kit-ruby)
beef2f9 @technomancy Oops; ruby-flymake needs to be done in eval-after-load.
technomancy authored
104 ;; starter-kit-ruby.el ends here
Something went wrong with that request. Please try again.