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