-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathold-init.el
424 lines (333 loc) · 12.6 KB
/
old-init.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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
;;; My emacs.d init file.
;;; <brad@intranation.com>
;; Turn off chrome
(dolist (mode '(menu-bar-mode tool-bar-mode scroll-bar-mode))
(when (fboundp mode) (funcall mode -1)))
;; inhibit startup screen
(setq inhibit-startup-screen t
;; Show *scratch* on start
initial-buffer-choice t)
;; start a server, unless one is already running
(when (require 'server nil t)
(unless (server-running-p)
(server-start)))
;; base load path
(defconst dotfiles-dir
(file-name-directory
(or (buffer-file-name) load-file-name))
"Base path for customised Emacs configuration")
(add-to-list 'load-path dotfiles-dir)
(require 'utils)
;; tmp directory for storing non-config things
(make-directory (setq tmp-local-dir (bw/join-dirs dotfiles-dir ".tmp")) t)
;; My font
(when (and (display-graphic-p) (find-font (font-spec :name "Inconsolata")))
(set-frame-font "Inconsolata-18" t t))
;; always highlight syntax
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(setq-default cursor-type 'bar)
;; Always show line number in the mode line
(line-number-mode 1)
;; ... and show the column number
(column-number-mode 1)
;; I don't type double-space sentences. This also affects fill-paragraph's
;; behaviour, so worth getting it right.
(set-default 'sentence-end-double-space nil)
;; wrap at 80 columns - 70 is mad
(setq-default fill-column 80)
;; UTF-8 FTW
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; always add a trailing newline - POSIX
(setq require-final-newline t)
;; nuke trailing whitespace when writing to a file
(add-hook 'write-file-hooks 'delete-trailing-whitespace)
;; I got sick of typing "yes"
(defalias 'yes-or-no-p 'y-or-n-p)
;; Default indentation
(setq-default
;; no tabs
indent-tabs-mode nil
;; 4 spaces
tab-width 4)
;; Don't clobber things in the system clipboard when killing
(setq save-interprogram-paste-before-kill t)
(when (display-graphic-p)
;; show help in the echo area instead of as a tooltip
(tooltip-mode -1)
;; never pop a dialogue box
(setq use-dialog-box nil)
;; From:
;; http://emacs-fu.blogspot.co.uk/2011/01/setting-frame-title.html
(setq frame-title-format
'((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b")))))
;; blink the cursor
(setq blink-cursor-interval 1.0)
(blink-cursor-mode 1)
;; show keystrokes immediately
(setq echo-keystrokes 0.1)
;; OSX specific overrides
(when (eq system-type 'darwin)
;; Mac hostnames have .local or similar appended
(setq system-name (car (split-string system-name "\\.")))
;; OSX ls doesn't support --dired
(setq dired-use-ls-dired nil)
;; get OS X version from command line
(setq bw/osx-version (bw/chomp (shell-command-to-string "sw_vers | grep ProductVersion | awk '{print $2}'")))
;; use aspell for spelling if it's available
(when (executable-find "aspell")
(setq ispell-program-name (executable-find "aspell")))
;; OSX in a GUI
(when (display-graphic-p)
;; This makes left-option do M-
(setq ns-alternate-modifier 'meta)
;; ... and right-option just do option so I can still type
;; alternate characters.
(setq ns-right-alternate-modifier nil)
;; command is super
(setq ns-command-modifier 'super)
;; set fn to hyper
(setq ns-function-modifier 'hyper)
;; Always use native fullscreen on Mavericks
(setq ns-use-native-fullscreen (string-match "^10\\.9" bw/osx-version))
;; Use proper sRGB
;; http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00741.html
(setq ns-use-srgb-colorspace t)
(when (fboundp 'toggle-frame-fullscreen)
(global-set-key (kbd "s-<return>") 'toggle-frame-fullscreen)))
(unless (display-graphic-p)
;; Configuration to make Emacs run semi-normally in an OS X
;; terminal
;; XXX: strongly recommended to run in iTerm2, as it's more
;; configurable than Terminal.app.
;; Make sure cut/paste works properly. Gotten from:
;; http://mindlev.wordpress.com/2011/06/13/emacs-in-a-terminal-on-osx/#comment-20
(defun bw/copy-from-osx ()
"Copies the current clipboard content using the `pbcopy` command"
(shell-command-to-string "pbpaste"))
(defun bw/paste-to-osx (text &optional push)
"Copies the top of the kill ring stack to the OSX clipboard"
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
;; Override defaults to use the mac copy and paste
(setq interprogram-cut-function 'bw/paste-to-osx)
(setq interprogram-paste-function 'bw/copy-from-osx)))
;; smart beginning-of-line, from:
;; http://irreal.org/blog/?p=1946
(defadvice move-beginning-of-line (around smarter-bol activate)
;; Move to requested line if needed.
(let ((arg (or (ad-get-arg 0) 1)))
(when (/= arg 1)
(forward-line (1- arg))))
;; Move to indentation on first call, then to actual BOL on second.
(let ((pos (point)))
(back-to-indentation)
(when (= pos (point))
ad-do-it)))
;; I want to use narrowing
(put 'narrow-to-defun 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-region 'disabled nil)
;; I want to use scrolling
(put 'scroll-left 'disabled nil)
;; Show bell instead of making a sound
(setq visible-bell t)
;; Conditionally ring the bell
(setq ring-bell-function
(lambda ()
"Only rings the bell if it's not a valid quit case, e.g
keyboard-quit"
(unless (memq this-command
'(isearch-abort abort-recursive-edit exit-minibuffer keyboard-quit))
(ding))))
;; stop allowing point over minibuffer prompt
;; http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html
(setq minibuffer-prompt-properties (add-to-list 'minibuffer-prompt-properties 'minibuffer-avoid-prompt))
(setq minibuffer-prompt-properties (add-to-list 'minibuffer-prompt-properties 'point-entered))
;;; Remap execute-extended-command
;; This is Yegge's advice
(global-unset-key (kbd "C-x m"))
(global-unset-key (kbd "M-x"))
(global-set-key (kbd "C-x m") 'execute-extended-command)
;; fat finger version
(global-set-key (kbd "C-x C-m") 'execute-extended-command)
;;; Remap yank/kill
;; Copy readline's kill word
(global-set-key (kbd "C-w") 'backward-kill-word)
;; Since we've unset C-w, map it to something else
(global-set-key (kbd "C-x C-k") 'kill-region)
;; ... and the clumsy version
(global-set-key (kbd "C-c C-k") 'kill-region)
(global-set-key (kbd "C-c y") 'bury-buffer)
(global-set-key (kbd "C-c r") 'revert-buffer)
(global-set-key (kbd "M-o") 'other-window)
;; indent automatically
(add-hook 'prog-mode-hook 'bw/turn-on-electric-indent-mode)
;; Add parts of each file's directory to the buffer name if not unique
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;;; ediff mode
(setq
;; make two side-by-side windows
ediff-split-window-function 'split-window-horizontally
;; ignore whitespace diffs
ediff-diff-options "-w"
;; Do everything in one frame always
ediff-window-setup-function 'ediff-setup-windows-plain)
;;; ido
(after-load 'ido
(ido-mode t)
(ido-everywhere t)
;; Ignore shitty Dropbox icon stuff:
;; http://stackoverflow.com/a/11341239/61435
(add-to-list 'ido-ignore-files "Icon\n")
;; configure ido
(setq
;; Speed up ido by using less candidates
ido-max-prospects 10
;; Match arbitrary points in strings
ido-enable-prefix nil
;; Match across entire string
ido-enable-flex-matching t
;; Create a new buffer if there's no match candidate
ido-create-new-buffer 'always
;; Don't try and guess if the string under point is a file
ido-use-filename-at-point nil
;; case-insensitive matching
ido-case-fold t
;; go back in time if required
ido-use-virtual-buffers nil))
(require 'ido)
;;; bookmarks
(after-load 'bookmark
;; make the file location consistent
(setq bookmark-default-file (expand-file-name ".emacs.bmk" tmp-local-dir)))
;; recently opened files
(after-load 'recentf
(setq
recentf-auto-cleanup 'never
recentf-exclude '("[/\\]\\.elpa/" "[/\\]\\.ido\\.last\\'" "[/\\]\\.git/" ".*\\.gz\\'" ".*-autoloads\\.el\\'" "[/\\]archive-contents\\'" "[/\\]\\.loaddefs\\.el\\'" "url/cookies" ".*\\emacs.bmk\\'")
;; save 100 most recent files
recentf-max-saved-items 100
;; keep recent files in consistent place
recentf-save-file (expand-file-name ".recentf" tmp-local-dir))
;; enable recentf
(recentf-mode 1)
;; strip $HOME from the front of recentf candidate files
(add-to-list 'recentf-filename-handlers 'abbreviate-file-name)
;; handle recent candidates with ido
(after-load 'ido
(defun bw/recentf-ido-find-file ()
"Find a recent file using ido."
(interactive)
(let ((file (ido-completing-read "Recently: " recentf-list nil t)))
(when file
(find-file file))))
(global-set-key (kbd "C-x C-r") 'bw/recentf-ido-find-file)))
(require 'recentf)
;; Hippie expand - auto-completion mechanism
;; Use hippie-expand instead of dabbrev
(global-set-key (kbd "M-/") 'hippie-expand)
;; make hippie expand behave itself
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))
;; emacs lisp configuration
;; automatically document the Emacs Lisp functions and variables under
;; point
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
;;; ansi-term configuration
;; force ansi-term to be utf-8 after it launches
(defadvice ansi-term (after advise-ansi-term-coding-system activate)
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))
;; close the terminal buffer automatically on exit
(defadvice term-sentinel (around my-advice-term-sentinel (proc msg) activate)
(if (memq (process-status proc) '(signal exit))
(let ((buffer (process-buffer proc)))
ad-do-it
(kill-buffer buffer))
ad-do-it))
;;; backup and autosave configuration
(make-directory (setq tmp-backups-dir (bw/join-dirs tmp-local-dir "backups")) t)
(make-directory (setq tmp-autosaves-dir (bw/join-dirs tmp-local-dir "autosaves")) t)
(setq
;; don't clobber symlinks
backup-by-copying t
;; copy into temporary directory
backup-directory-alist `((".*" . ,tmp-backups-dir))
;; copy into autosaves directory
auto-save-file-name-transforms `((".*" ,tmp-autosaves-dir t))
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
;; Use versioned backups
version-control t)
;;; python-mode - Python major mode
(add-hook 'python-mode-hook 'bw/turn-on-subword-mode)
;;; tramp-mode - Edit files remotely
(after-load 'tramp
;; use SSH by default
(setq tramp-default-method "ssh")
;; allow me to SSH to hosts and edit as sudo like:
;; C-x C-f /sudo:example.com:/etc/something-owned-by-root
;; from: http://www.gnu.org/software/tramp/#Multi_002dhops
(add-to-list 'tramp-default-proxies-alist
'(nil "\\`root\\'" "/ssh:%h:"))
(add-to-list 'tramp-default-proxies-alist
'((regexp-quote (system-name)) nil nil)))
;;; org-mode
;; Don't auto-fold my documents
(setq org-startup-folded nil)
;; Show other programming languages semi-natively when embedded
(org-babel-do-load-languages
'org-babel-load-languages
;; load emacs-lisp natively
'((emacs-lisp . t)))
;; edit inline code blocks natively
(setq org-src-fontify-natively t)
(setq org-src-tab-acts-natively t)
;;; eshell-mode
(setq eshell-directory-name (bw/join-dirs tmp-local-dir "eshell"))
(after-load 'esh-opt
;; when SSHing into another box, open in ansi-term as eshell won't be
;; supported
(require 'em-term)
(add-to-list 'eshell-visual-commands "ssh")
;; vagrant ssh is similar
(add-to-list 'eshell-visual-subcommands '("vagrant" "ssh")))
;; `e` opens a file
(defun eshell/e (file)
(find-file file))
(global-set-key (kbd "C-c C-t e") 'eshell)
;;; ruby-mode
(after-load 'ruby-mode
;; why subword-mode isn't on by default for ruby-mode I don't understand
(add-hook 'ruby-mode-hook 'bw/turn-on-subword-mode))
;;; ELPA customisation and installation
(require 'setup-elpa)
;;; Load system specific code
(setq local-dotfiles-dir (bw/join-dirs dotfiles-dir "local"))
(setq
bw/user-config (concat local-dotfiles-dir user-login-name ".el")
bw/system-config (concat local-dotfiles-dir system-name ".el"))
(when (file-exists-p bw/user-config)
(load bw/user-config))
(when (file-exists-p bw/system-config)
(load bw/system-config))
;; Load custom file last
(setq custom-file (concat dotfiles-dir "custom.el"))
(load custom-file 'noerror)