Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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