Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 91 lines (71 sloc) 3.245 kb
5fcb34d @technomancy initial commit
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.
authored
5 (eval-after-load 'ruby-mode
6 '(progn
7 (require 'ruby-compilation)
680a6d6 @technomancy ruby-compilation cleanups.
authored
8 (add-hook 'ruby-mode-hook 'inf-ruby-keys)
f821261 @technomancy Autoload and invoke paredit. Fix ruby-mode RET.
authored
9 (define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
1f6f58b @technomancy Extracted cleanup buffer function.
authored
10 (define-key ruby-mode-map (kbd "C-M-h") 'backward-kill-word)
12ac2f0 @technomancy Rearrange lisp and ruby helpers.
authored
11 (define-key ruby-mode-map (kbd "C-c l") "lambda")))
5fcb34d @technomancy initial commit
authored
12
13 (global-set-key (kbd "C-h r") 'ri)
14
9eedd2e @technomancy Gemspecs are ruby code.
authored
15 ;; Rake files are ruby, too, as are gemspecs.
b4aa114 @technomancy Added some rake functions.
authored
16 (add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
17 (add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
9eedd2e @technomancy Gemspecs are ruby code.
authored
18 (add-to-list 'auto-mode-alist '("\\.gemspec$" . ruby-mode))
b4aa114 @technomancy Added some rake functions.
authored
19
5fcb34d @technomancy initial commit
authored
20 ;; We never want to edit Rubinius bytecode
21 (add-to-list 'completion-ignored-extensions ".rbc")
22
b4aa114 @technomancy Added some rake functions.
authored
23 ;;; Rake
24
25 (defun pcomplete/rake ()
26 "Completion rules for the `ssh' command."
27 (pcomplete-here (pcmpl-rake-tasks)))
28
29 (defun pcmpl-rake-tasks ()
30 "Return a list of all the rake tasks defined in the current
31 projects. I know this is a hack to put all the logic in the
32 exec-to-string command, but it works and seems fast"
33 (delq nil (mapcar '(lambda(line)
34 (if (string-match "rake \\([^ ]+\\)" line) (match-string 1 line)))
35 (split-string (shell-command-to-string "rake -T") "[\n]"))))
36
37 (defun rake (task)
38 (interactive (list (completing-read "Rake (default: default): "
39 (pcmpl-rake-tasks))))
40 (shell-command-to-string (concat "rake " (if (= 0 (length task)) "default" task))))
41
42
838e8f9 @technomancy Clear compilation buffer in between test runs.
authored
43 ;; Clear the compilation buffer between test runs.
44 (eval-after-load 'ruby-compilation
45 '(progn
46 (defadvice ruby-do-run-w/compilation (before kill-buffer (name cmdlist))
47 (let ((comp-buffer-name (format "*%s*" name)))
48 (when (get-buffer comp-buffer-name)
49 (with-current-buffer comp-buffer-name
50 (delete-region (point-min) (point-max))))))
51 (ad-activate 'ruby-do-run-w/compilation)))
52
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
53 (add-hook 'ruby-mode-hook 'coding-hook)
38ac75b @technomancy Remove cheat binding, use coding-hook.
authored
54
eb4d3d5 @technomancy Set up flymake for ruby files.
authored
55 ;;; Flymake
56
57 (eval-after-load 'ruby-mode
58 '(progn
59 (require 'flymake)
60
61 ;; Invoke ruby with '-c' to get syntax checking
62 (defun flymake-ruby-init ()
63 (let* ((temp-file (flymake-init-create-temp-buffer-copy
64 'flymake-create-temp-inplace))
65 (local-file (file-relative-name
66 temp-file
67 (file-name-directory buffer-file-name))))
68 (list "ruby" (list "-c" local-file))))
69
70 (push '(".+\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks)
71 (push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks)
72
73 (push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3)
74 flymake-err-line-patterns)
75
76 (add-hook 'ruby-mode-hook
77 (lambda ()
78 (when (and buffer-file-name
79 (file-writable-p
80 (file-name-directory buffer-file-name))
81 (file-writable-p buffer-file-name))
82 (local-set-key (kbd "C-c d")
83 'flymake-display-err-menu-for-current-line)
84 (flymake-mode t))))))
85
5fcb34d @technomancy initial commit
authored
86 ;; TODO: set up ri
87 ;; TODO: electric
88
89 (provide 'starter-kit-ruby)
beef2f9 @technomancy Oops; ruby-flymake needs to be done in eval-after-load.
authored
90 ;; starter-kit-ruby.el ends here
Something went wrong with that request. Please try again.