Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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