-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkevins-emacs-custom.el
More file actions
360 lines (288 loc) · 12.1 KB
/
kevins-emacs-custom.el
File metadata and controls
360 lines (288 loc) · 12.1 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; KEVIN ALBRECHT, 2014-11-26
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Installing Emacs
;; ----------------
;; Mac OS X: http://emacsformacosx.com/builds
;; Windows: http://code.google.com/p/emacs-for-windows/downloads/list
;; Debian: http://emacs.naquadah.org/
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Setting up this file
;; --------------------
;;
;; 1. Find your emacs init file in one of the following locations:
;; ~/.emacs
;; ~/AppData/Roaming/.emacs.d/init.el
;; ~/.emacs.d/init.el
;;
;; 2. Add the following lines to your emacs init file that you found
;; in step 1, above (change my-user-name to something else if the
;; username on that computer is different than "kevin"):
;;
;; (defvar my-user-name "kevin")
;; (add-to-list 'load-path "~/code/personal-settings")
;; (load-library "~/code/personal-settings/kevins-emacs-custom.el")
;;
;; 3. On Windows, install cygwin and then set the system PATH variable
;; to have C:\cygwin\bin as the first thing on the PATH
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;---------- Setup
;; Operating system
(defvar is-system-windows (string-match "windows" (symbol-name system-type)))
(defvar is-system-mac (string-match "darwin" (symbol-name system-type)))
(defvar is-system-linux (string-match "gnu/linux" (symbol-name system-type)))
;; Home directory
(defvar home-dir
(cond (is-system-mac (concat "/Users/" my-user-name "/"))
(is-system-linux (concat "/home/" my-user-name "/"))
(is-system-windows (concat "C:/Users/" my-user-name "/"))))
;; Emacs directory
(defvar emacs-dir
(cond (is-system-mac (concat home-dir ".emacs.d/"))
(is-system-linux (concat home-dir ".emacs.d/"))
(is-system-windows (concat home-dir "AppData/Roaming/.emacs.d/"))))
(defvar emacs-extras-dir
(concat emacs-dir "extras/"))
(defvar emacs-vendor-dir
(concat emacs-dir "vendor/"))
(defvar themes-dir
(concat emacs-dir "themes/"))
(defvar theme-extras-dir
(concat emacs-dir "theme-extras/"))
(defvar code-dir
(concat home-dir "code/"))
;;---------- Helper functions
(defun download-if-missing (file-path url-path)
(if (not (file-exists-p file-path))
(progn
(url-copy-file url-path file-path))))
(defun create-directory-if-missing (path)
(if (not (file-accessible-directory-p path))
(progn
(make-directory path))))
;;---------- Initialize marmalade package manager
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
;;---------- Auto-install marmelade packages at startup if not found
(when (not package-archive-contents)
(package-refresh-contents))
;; Add in your own as you wish. If one of these fails, try M-x
;; package-refresh-contents to update the list of packages from ELPA
;; and marmalade.
;;
;; To upgrade all installed packages, try M-x package-list-packages,
;; then press "U" followed by "x"
(defvar my-packages '(starter-kit ;; the Emacs Starter Kit
starter-kit-lisp ;; for generic Lisp support
clojure-mode ;; for Clojure
;;cider ;; for Clojure (formerly nREPL)
markdown-mode ;; for the Markdown markup language
go-mode ;; for the Go programming lang
rainbow-delimiters
auto-complete
ac-nrepl ;; for Clojure, https://github.com/purcell/ac-nrepl
projectile ;; https://github.com/bbatsov/projectile
ruby-mode
web-mode
js2-mode
coffee-mode ;; for Coffeescript
)
"A list of packages to ensure are installed at launch.")
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
;;---------- Projectile (project support)
(projectile-global-mode)
;;---------- Emacs Extras & Vendor Directories
(create-directory-if-missing emacs-extras-dir)
(add-to-list 'load-path emacs-extras-dir)
(create-directory-if-missing emacs-vendor-dir)
(add-to-list 'load-path emacs-vendor-dir)
;;---------- Rainbow Delimiters enabled in all languages
(global-rainbow-delimiters-mode)
;;---------- Color theme setup
;; Theme extra directory (support files that must be on the load path)
(create-directory-if-missing theme-extras-dir)
(add-to-list 'load-path theme-extras-dir)
;; Themes directory
(create-directory-if-missing themes-dir)
(add-to-list 'custom-theme-load-path themes-dir)
;; Zenburn
(download-if-missing (concat themes-dir "zenburn-theme.el")
"https://raw.github.com/bbatsov/zenburn-emacs/master/zenburn-theme.el")
;; Solarized #1: https://github.com/bbatsov/solarized-emacs
(download-if-missing (concat theme-extras-dir "solarized.el")
"https://raw.github.com/bbatsov/solarized-emacs/master/solarized.el")
(download-if-missing (concat themes-dir "solarized-dark-theme.el")
"https://raw.github.com/bbatsov/solarized-emacs/master/solarized-dark-theme.el")
(download-if-missing (concat themes-dir "solarized-light-theme.el")
"https://raw.github.com/bbatsov/solarized-emacs/master/solarized-light-theme.el")
;; Solarized #2: https://github.com/sellout/emacs-color-theme-solarized
;; (download-if-missing (concat themes-dir "color-theme-solarized-pkg.el")
;; "https://raw.github.com/sellout/emacs-color-theme-solarized/master/color-theme-solarized-pkg.el")
;; (download-if-missing (concat themes-dir "color-theme-solarized.el")
;; "https://raw.github.com/sellout/emacs-color-theme-solarized/master/color-theme-solarized.el")
;; (download-if-missing (concat themes-dir "solarized-dark-theme.el")
;; "https://raw.github.com/sellout/emacs-color-theme-solarized/master/solarized-dark-theme.el")
;; (download-if-missing (concat themes-dir "solarized-light-theme.el")
;; "https://raw.github.com/sellout/emacs-color-theme-solarized/master/solarized-light-theme.el")
;; (download-if-missing (concat themes-dir "solarized-definitions.el")
;; "https://raw.github.com/sellout/emacs-color-theme-solarized/master/solarized-definitions.el")
;;-- Load a theme
;;(load-theme 'zenburn 't)
;;(load-theme 'solarized-light 't)
(load-theme 'solarized-dark 't)
;;---------- FONT SETUP
(if is-system-windows
(set-face-attribute 'default nil :font "Bitstream Vera Sans Mono-9"))
(if is-system-mac
(set-face-attribute 'default nil :font "Bitstream Vera Sans Mono-14"))
(if is-system-linux
(set-face-attribute 'default nil :font "Bitstream Vera Sans Mono-10"))
(setq-default indent-tabs-mode nil)
;; Turn off wrapping
(setq-default truncate-lines 't)
;;---------- FILE SYSTEM
;; Default directory
(cd code-dir)
(setq default-directory code-dir)
;;---------- WEB-MODE SUPPORT
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
;; Turn off auto
(remove-hook 'web-mode-hook #'turn-on-auto-fill)
;;---------- RUBY SUPPORT
(add-hook 'ruby-mode-hook
'auto-complete-mode)
;;---------- GO SUPPORT
;; This requires go-autocomplete to be installed with "go get" to
;; correctly work. See: https://github.com/nsf/gocode
(if is-system-windows
(progn
(download-if-missing (concat emacs-extras-dir "go-autocomplete.el")
"https://raw.github.com/nsf/gocode/master/emacs/go-autocomplete.el")
(require 'go-autocomplete)
(require 'auto-complete-config)))
;;---------- Clojure support
;; 1. Install leiningen: http://leiningen.org/
;;
;; Using jump mode:
;; 1. Open a Clojure file
;; 2. Start nREPL: M-x nrepl-jack-in
;; 3. Load the namespace: C-c C-n
;; 4. Go to a form and use: M-.
;; Improve indentaion
(require 'clojure-mode)
(define-clojure-indent
(describe 1) ; for speclj
(it 1) ; for speclj
(dosync 0)
(io! 0)
(try+ 0) ; for slingshot
(in 1) ; for waltz
(out 1) ; for waltz
)
;; For nREPL mode
(add-hook 'clojure-mode-hook
'nrepl-interaction-mode)
;; Enable eldoc in Clojure buffers
(add-hook 'nrepl-interaction-mode-hook
'nrepl-turn-on-eldoc-mode)
;; Enable Paredit in nREPL buffers
(add-hook 'nrepl-mode-hook 'paredit-mode)
;; Enable rainbow delimiters mode in nREPL buffers
(add-hook 'nrepl-mode-hook 'rainbow-delimiters-mode)
;; Autocomplete support for Clojure
(require 'auto-complete)
(require 'ac-nrepl)
(add-hook 'nrepl-mode-hook 'ac-nrepl-setup)
(add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup)
(eval-after-load "auto-complete"
'(add-to-list 'ac-modes 'nrepl-mode))
(add-hook 'clojure-mode-hook
'auto-complete-mode)
;; Trigger auto-complete using TAB in nrepl buffers
(defun set-auto-complete-as-completion-at-point-function ()
(setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
(add-hook 'nrepl-mode-hook 'set-auto-complete-as-completion-at-point-function)
(add-hook 'nrepl-interaction-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;---------- ClojureScript support
(setq auto-mode-alist (cons '("\\.cljs" . clojure-mode) auto-mode-alist))
;;---------- JavaScript support
(add-hook 'js-mode-hook
'auto-complete-mode)
(remove-hook 'js-mode-hook #'turn-on-auto-fill)
(setq js-indent-level 2)
;;---------- CoffeeScript support
;; Installation:
;;
;; 1. Install NPM
;; ( see https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager )
;;
;; sudo apt-get update
;; sudo add-apt-repository ppa:chris-lea/node.js
;; sudo apt-get update
;; sudo apt-get install nodejs=0.8.18-1chl1~precise1
;;
;; 2. Install CoffeeScript
;;
;; sudo npm install -g coffee-script
(require 'auto-complete)
(defun turn-on-whitespace-action-and-style ()
(setq whitespace-action '(auto-cleanup)) ;; automatically clean up bad whitespace
(setq whitespace-style '(trailing space-before-tab indentation empty space-after-tab)) ;; only show bad whitespace
)
(add-hook 'coffee-mode-hook 'turn-on-whitespace-action-and-style)
(add-hook 'coffee-mode-hook 'auto-complete-mode)
;;---------- Markdown support
(setq auto-mode-alist (cons '("\\.text" . markdown-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.md" . markdown-mode) auto-mode-alist))
;;---------- Mac Keyboard Support
;; This allows use of the Alt/Option key for international use on Mac:
;; ctrl = C
;; alt/option = not bound in emacs, allows this to be used for other characters
;; cmd = M
;;
;; See:
;; http://stackoverflow.com/questions/3376863/unable-to-type-braces-and-square-braces-in-emacs
(if is-system-mac
(progn
(setq mac-option-modifier nil
mac-command-modifier 'meta
x-select-enable-clipboard t)))
;;---------- Find/Grep Support
;; Prevent issues with the Windows null device (NUL)
;; when using cygwin find with rgrep.
;; From http://emacswiki.org/emacs/NTEmacsWithCygwin
(if is-system-windows
(progn
(defadvice grep-compute-defaults (around grep-compute-defaults-advice-null-device)
"Use cygwin's /dev/null as the null-device."
(let ((null-device "/dev/null"))
ad-do-it))
(ad-activate 'grep-compute-defaults)))
;;---------- Misc Settings
(setq column-number-mode t)
(setq default-tab-width 4)
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
;; Automatically revert files that are updated outside of the editor
(global-auto-revert-mode)