forked from technomancy/emacs-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modes.el
167 lines (141 loc) · 5.9 KB
/
modes.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
;; Ack
(use-package ack-and-a-half
:init (progn
(add-to-list 'safe-local-variable-values
'(ack-and-a-half-arguments . t)))
:bind ("C-c C-f" . ack-and-a-half)
:config (progn
(add-hook 'eproject-first-buffer-hook (lambda ()
(when (eproject-root)
(set (make-local-variable
'ack-and-a-half-root-directory-functions)
'ack-and-a-half-root-directory-functions)
(add-to-list 'ack-and-a-half-root-directory-functions
'eproject-root))))))
(use-package go-mode
:config (progn (setq-default tab-width 4)
;; auto-format my Golang files correctly
(add-hook 'before-save-hook 'gofmt-before-save)))
;; eproject mode
(use-package eproject
:config (progn
;; ruby on rails special type
(define-project-type ruby-on-rails-git (generic-git)
(and (look-for ".git")
(look-for "Gemfile")
(look-for "config/application.rb"))
:main-file "Gemfile")
(defun rails-eproject-test (&optional only-this-file)
"Runs local tests"
(interactive "P")
(if (eq only-this-file nil)
(compile "bundle exec rake" t)
(compile (concat "bundle exec ruby -I test " (buffer-file-name)) t)))
(defun rails-eproject-hook ()
"Set up some local variables"
(add-to-list 'safe-local-variable-values '(scss-sass-command . t))
(set (make-local-variable 'inf-ruby-default-implementation) "bundle-ruby")
;; run rake to compile
(set (make-local-variable 'compile-command) "bundle exec rake")
(local-set-key (kbd "C-c C-t") 'rails-eproject-test))
(add-hook 'ruby-on-rails-git-project-file-visit-hook 'rails-eproject-hook)
(defun bw-eproject-find-files ()
"If we're in a Git project, use git ls-files to look up the files, because it won't try to open any .gitignored files."
(interactive)
(if (member (eproject-type) '(generic-git ruby-on-rails-git))
(let ((default-directory (eproject-root)))
(find-file
(concat
(eproject-root)
(ido-completing-read
(format "Find file: %s" (eproject-root))
(split-string (shell-command-to-string "git ls-files"))))))
(eproject-find-file)))
(use-package eproject-extras
:bind ("C-c f" . bw-eproject-find-files))
(setq eproject-completing-read-function 'eproject--ido-completing-read)))
;; IDO mode
(use-package ido
:init (ido-mode t)
:config (progn
(setq
ido-enable-prefix nil
ido-enable-flex-matching t
ido-create-new-buffer 'always
ido-use-filename-at-point nil
ido-max-prospects 20
ido-case-fold t)))
;; JavaScript
(use-package js2-mode
:mode ("\\.js\\'" . js2-mode)
:config (progn
;; Camel case is popular in JS
(subword-mode)
(setq
;; highlight everything
js2-highlight-level 3
;; 4 space indent
js2-basic-offset 4
;; idiomatic closing bracket position
js2-consistent-level-indent-inner-bracket-p t
;; allow for multi-line var indenting
js2-pretty-multiline-decl-indentation-p t
;; Don't highlight missing variables in js2-mode: we have jslint for
;; that
js2-highlight-external-variables nil
;; jslint shows missing semi-colons
js2-strict-missing-semi-warning nil)))
;; JSON files
(use-package json-mode
:mode ("\\.json\\'" . json-mode))
(use-package sass-mode
:mode ("\\.scss\\'" . sass-mode))
;; markdown
(use-package markdown-mode
:mode (("\\.md$" . markdown-mode)
("\\.markdown$" . markdown-mode)))
(use-package nginx-mode
:mode ("\\.conf\\'" . nginx-mode))
;; Puppet manifests
(use-package puppet-mode
:mode ("\\.pp$" . puppet-mode))
;; ERB templates
(use-package rhtml-mode
:mode (("\\.rhtml$" . rhtml-mode)
("\\.erb$" . rhtml-mode)))
;; Ruby mode
(use-package ruby-mode
:mode (("\\.rabl$" . ruby-mode)
("\\.rake$" . ruby-mode)
("\\.rb\\'" . ruby-mode)
("\\.rhtml\\'" . ruby-mode)
("\\.rsel\\'" . ruby-mode)
("\\.prawn\\'" . ruby-mode)
("[vV]agrantfile$" . ruby-mode)
("[gG]emfile$" . ruby-mode)
("[rR]akefile$" . ruby-mode))
:config (progn
;; Rails project setup
(defun eproject-rails-config ()
"Various settings for Rails projects"
;; We don't want to compile SCSS in Rails because the asset pipeline
;; does it for us
(set (make-local-variable 'scss-compile-at-save) nil))
(add-hook 'ruby-on-rails-project-file-visit-hook 'eproject-rails-config)
;; Ruby has a lot of camel case
(subword-mode)
;; this variable is stupid - apparently Ruby needs its own indent
(setq ruby-indent-level 2)))
;; add a bundle version of IRB shell
(use-package rinari
:config
(progn
(add-to-list 'inf-ruby-implementations
'("bundle-ruby" . "bundle exec irb --inf-ruby-mode -r irb/completion"))))
(use-package ruby-test-mode)
;; Stops the annoying jump when moving around.
(use-package smooth-scroll)
;; YAML mode
(use-package yaml-mode
:mode (("\\.yml$" . yaml-mode)
("\\.yaml$" . yaml-mode)))