Permalink
Newer
100644
495 lines (469 sloc)
13.7 KB
1
#+TITLE: A literate emacs configuration
2
3
* Packages
4
** Set up package archives: live on the bleeding edge.
5
#+BEGIN_SRC emacs-lisp
6
(require 'package)
7
(setq package-archives '(("melpa" . "http://melpa.milkbox.net/packages/")
8
("elpa" . "http://elpa.gnu.org/packages/")
9
("org" . "http://orgmode.org/elpa/")))
10
(package-initialize)
11
#+END_SRC
12
** TODO Use =use-package=
13
List out all packages and install them if they're available.
14
15
* Customization
17
** Move the file out of init.el
18
#+BEGIN_SRC emacs-lisp
19
(setq custom-file "~/.emacs.d/custom.el")
20
(load custom-file 'noerror)
21
#+END_SRC
22
23
* UI
24
** Minimal UI
25
Do this first to try to get the flicker in the gui out of the way quickly
26
#+BEGIN_SRC emacs-lisp
27
(tool-bar-mode -1)
28
(menu-bar-mode -1)
29
(if (boundp 'fringe-mode)
30
(fringe-mode -1))
31
(if (boundp 'scroll-bar-mode)
32
(scroll-bar-mode -1))
33
#+END_SRC
34
** Mouse support
35
#+BEGIN_SRC emacs-lisp
36
(xterm-mouse-mode)
37
#+END_SRC
38
** Improve theme loading; [[https://www.reddit.com/r/emacs/comments/4mzynd/what_emacs_theme_are_you_currently_using/d43c5cw][from reddit]]
39
#+BEGIN_SRC emacs-lisp
40
(defadvice load-theme (before clear-previous-themes activate)
41
"Clear existing theme settings instead of layering them"
42
(mapc #'disable-theme custom-enabled-themes))
43
#+END_SRC
45
#+BEGIN_SRC emacs-lisp
46
(set-face-attribute 'default nil :family "Iosevka" :height 130)
47
(set-face-attribute 'fixed-pitch nil :family "Iosevka" :height 130)
48
(set-face-attribute 'variable-pitch nil :family "Baskerville")
50
** And a minimal startup
51
#+BEGIN_SRC emacs-lisp
52
(setq inhibit-startup-message t)
53
(setq inhibit-splash-screen t)
54
(setq initial-scratch-message nil)
55
#+END_SRC
56
** Disable the bell
57
#+BEGIN_SRC emacs-lisp
58
(setq ring-bell-function 'ignore)
59
#+END_SRC
60
** Buffer Switching
61
#+BEGIN_SRC emacs-lisp
62
(winner-mode t)
63
#+END_SRC
64
** Display line numbers mode
65
*** Activate on programming modes
69
#+END_SRC
70
71
** Fill column
72
#+BEGIN_SRC emacs-lisp
73
(setq fci-rule-column 80)
74
#+END_SRC
75
** Scrolling more naturally
76
#+BEGIN_SRC emacs-lisp
80
** Compilation window output
81
#+BEGIN_SRC emacs-lisp
82
(setq compilation-window-height 15)
83
#+END_SRC
86
(add-hook 'prog-mode
87
(lambda ()
88
(setq-default truncate-lines t)))
90
** Sweet Title Bar
91
#+BEGIN_SRC emacs-lisp
92
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
93
(add-to-list 'default-frame-alist '(ns-appearance . light))
94
#+END_SRC
95
* Evil
96
** I can't type without vim bindings anymore.
97
#+BEGIN_SRC emacs-lisp
98
(evil-mode t)
99
#+END_SRC
100
** Allow some common typos
101
#+BEGIN_SRC emacs-lisp
102
(evil-ex-define-cmd "W[rite]" 'save-buffer)
103
(evil-ex-define-cmd "V[split]" 'evil-window-vsplit)
104
#+END_SRC
105
106
* Org
107
** Babel
109
#+BEGIN_SRC emacs-lisp
113
#+BEGIN_SRC emacs-lisp
114
(setq org-src-fontify-natively t)
115
(setq org-src-tab-acts-natively t)
116
(setq org-edit-src-content-indentation 0)
118
*** Highlight quotes
119
#+BEGIN_SRC emacs-lisp
120
(setq org-fontify-quote-and-verse-blocks t)
121
#+END_SRC
123
#+BEGIN_SRC emacs-lisp
124
(org-babel-do-load-languages
125
'org-babel-load-languages
126
'((emacs-lisp . t)
127
(dot . t)
128
(ditaa . t)
129
(python . t)
130
(C . t)
131
(rust . t)))
132
#+END_SRC
133
*** Prevent confirmation
134
#+BEGIN_SRC emacs-lisp
135
(setq org-confirm-babel-evaluate nil)
136
#+END_SRC
137
*** Use Web mode for HTML
138
#+BEGIN_SRC emacs-lisp
139
(add-to-list 'org-src-lang-modes
140
'("html" . web))
141
#+END_SRC
142
** UI
143
*** Hide markers
144
#+BEGIN_SRC emacs-lisp
145
(setq org-hide-emphasis-markers t)
146
#+END_SRC
147
*** Clean bullets
148
#+BEGIN_SRC emacs-lisp
149
(setq org-bullets-bullet-list
150
'("◉" "○"))
151
(add-hook 'org-mode-hook
152
(lambda ()
153
(org-bullets-mode 1)
154
(org-indent-mode t)))
155
#+END_SRC
156
*** Display images
157
#+BEGIN_SRC emacs-lisp
158
(setq org-startup-with-inline-images t)
159
(add-hook
160
'org-babel-after-execute-hook
161
(lambda ()
162
(when org-inline-image-overlays
163
(org-redisplay-inline-images))))
164
#+END_SRC
165
*** Enable auto-fill mode
166
#+BEGIN_SRC emacs-lisp
167
(add-hook
168
'org-mode-hook
169
(lambda ()
170
(auto-fill-mode)))
171
#+END_SRC
172
*** Fontify whole lines
173
#+BEGIN_SRC emacs-lisp
174
(setq org-fontify-whole-heading-line t)
175
#+END_SRC
176
** Combined with evil
177
#+BEGIN_SRC emacs-lisp
178
(evil-define-key 'normal org-mode-map (kbd "TAB") 'org-cycle)
179
#+END_SRC
180
** Bugfixes
181
#+BEGIN_SRC emacs-lisp
182
(defun org-font-lock-ensure ()
183
(font-lock-fontify-buffer))
184
#+END_SRC
185
** Expert tagging
186
(Doesn't show the tag window till an extra C-c.)
187
#+BEGIN_SRC emacs-lisp
188
(setq org-fast-tag-selection-single-key 'expert)
189
#+END_SRC
190
** Tag clicks show sparse tree instead of agenda view
191
#+BEGIN_SRC emacs-lisp
192
(defun tag-at-point-in-heading ()
193
"Returns the tag at the current point in the string"
194
(let ((str (buffer-string))
195
(begin (point))
196
(end (point)))
197
(while (not (equal (aref str begin) ?:))
198
(setq begin (- begin 1)))
199
(while (not (equal (aref str end) ?:))
200
(setq end (+ end 1)))
201
(substring str (+ 1 begin) end)))
202
203
(defun open-sparse-view ()
204
"Shows a sparse tree on clicking a tag instead of org-tags-view"
205
;; From org-open-at-point, sanity checking that we're on a headline with tags
206
(when (and (org-element-lineage (org-element-context)
207
'(headline inlinetask)
208
t)
209
(progn (save-excursion (beginning-of-line)
210
(looking-at org-complex-heading-regexp))
211
(and (match-beginning 5)
212
(> (point) (match-beginning 5)))))
213
(org-match-sparse-tree nil (concat "+" (tag-at-point-in-heading)))
214
't))
215
216
(add-hook 'org-open-at-point-functions
217
'open-sparse-view)
219
** Add support for not exporting headlines
220
#+BEGIN_SRC emacs-lisp
221
(require 'ox-extra) ; from org-plus-contrib
222
(ox-extras-activate '(ignore-headlines))
223
#+END_SRC
224
** Add support for publishing 'web' src as is
225
#+BEGIN_SRC emacs-lisp
226
(defun org-babel-execute:web (body params)
227
body)
228
#+END_SRC
230
** Customization
231
#+BEGIN_SRC emacs-lisp
232
(setq emamux:use-nearest-pane t)
233
#+END_SRC
234
** Some useful shortcuts
235
#+BEGIN_SRC emacs-lisp
236
(define-key evil-normal-state-map (kbd "C-c r") 'emamux:run-last-command)
237
(define-key evil-normal-state-map (kbd "C-c x") 'emamux:run-command)
238
(define-key evil-normal-state-map (kbd "C-c i") 'emamux:inspect-runner)
240
* Compiling
241
** Keyboard shortcut
242
#+BEGIN_SRC emacs-lisp
243
(define-key evil-normal-state-map (kbd "C-c c") 'recompile)
244
#+END_SRC
245
* Man Pages
246
#+BEGIN_SRC emacs-lisp
247
(setq Man-notify-method 'pushy)
250
* Editing
251
** Indentation
252
#+BEGIN_SRC emacs-lisp
253
(setq c-basic-offset 2)
254
(setq tab-width 2)
255
(setq-default indent-tabs-mode nil)
256
#+END_SRC
257
** Backups & autosaves
258
#+BEGIN_SRC emacs-lisp
259
(setq auto-save-default nil)
260
(setq backup-directory-alist
261
`((".*" . ,temporary-file-directory)))
262
(setq auto-save-file-name-transforms
263
`((".*" ,temporary-file-directory t)))
264
#+END_SRC
265
** Better braces
266
*** [[https://github.com/Fuco1/smartparens][Smartparens]]
267
#+BEGIN_SRC emacs-lisp
268
(require 'smartparens-config)
269
(add-hook 'prog-mode-hook 'turn-on-smartparens-mode)
270
(define-key smartparens-mode-map (kbd "M-f") 'sp-forward-slurp-sexp)
271
(define-key smartparens-mode-map (kbd "M-b") 'sp-backward-slurp-sexp)
272
(define-key smartparens-mode-map (kbd "M-F") 'sp-forward-barf-sexp)
273
(define-key smartparens-mode-map (kbd "M-B") 'sp-backward-barf-sexp)
274
(define-key smartparens-mode-map (kbd "M-s") 'sp-splice-sexp)
275
(define-key smartparens-mode-map (kbd "C-k") 'sp-kill-sexp)
276
#+END_SRC
277
*** Highlight parenthesis
278
#+BEGIN_SRC emacs-lisp
279
(show-paren-mode t)
280
#+END_SRC
281
** Whitespace
282
#+BEGIN_SRC emacs-lisp
283
(add-hook 'before-save-hook 'whitespace-cleanup)
284
(setq require-final-newline t)
285
#+END_SRC
286
287
* Menus
288
** [[https://www.emacswiki.org/emacs/InteractivelyDoThings][IDO]]
289
#+BEGIN_SRC emacs-lisp
290
(setq ido-enable-flex-matching t)
291
(setq ido-everywhere t)
292
(ido-mode t)
293
#+END_SRC
294
** [[https://www.emacswiki.org/emacs/Smex][Smex]]
295
#+BEGIN_SRC emacs-lisp
296
(global-set-key (kbd "M-x") 'smex)
297
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
300
301
* Language/Project specific
302
** BUCK
303
*** Trigger python mode
304
#+BEGIN_SRC emacs-lisp
305
(add-to-list 'auto-mode-alist '(".*/BUCK$" . python-mode))
306
#+END_SRC
307
** Scheme
308
*** Set up chicken scheme
309
#+BEGIN_SRC emacs-lisp
310
(setq scheme-program-name "/usr/local/bin/csi -:c")
311
#+END_SRC
312
** Web Mode
313
#+BEGIN_SRC emacs-lisp
314
(setq web-mode-markup-indent-offset 2)
315
(setq web-mode-css-indent-offset 2)
316
(setq web-mode-code-indent-offset 2)
318
(setq web-mode-style-padding 2)
319
(setq web-mode-script-padding 2)
320
321
(setq web-mode-auto-quote-style 2) ; use single quotes
322
#+END_SRC
323
324
** Rust
325
#+BEGIN_SRC emacs-lisp
326
(add-hook 'rust-mode-hook #'racer-mode)
327
(add-hook 'rust-mode-hook
328
(lambda ()
329
(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)))
330
(add-hook 'racer-mode-hook #'eldoc-mode)
331
(add-hook 'flycheck-mode-hook #'flycheck-rust-setup)
332
#+END_SRC
333
334
* Version Control
335
** Disable by default
336
#+BEGIN_SRC emacs-lisp
337
(setq vc-handled-backends ())
338
#+END_SRC
339
** Customize Monky, for when it's loaded
340
*** Use command server for speed
341
#+BEGIN_SRC emacs-lisp
342
(setq monky-process-type 'cmdserver)
343
#+END_SRC
345
#+BEGIN_SRC emacs-lisp
346
(defun hg-file-history ()
347
(interactive)
348
(require 'monky)
349
(monky-run-hg-async
350
"log"
351
"--template"
352
"\n{rev}) {date|shortdate}/{author|user}\n{desc|fill68}\n↘\n"
353
buffer-file-name))
354
#+END_SRC
356
* Utilities
357
** Current file name
358
#+BEGIN_SRC emacs-lisp
359
(defun path ()
360
(interactive)
361
(message (buffer-file-name)))
362
#+END_SRC
364
* GDB
365
** Show all the windows on start
366
#+BEGIN_SRC emacs-lisp
367
(setq gdb-many-windows 't)
368
#+END_SRC
369
* Neotree
370
** Simple theme
371
#+BEGIN_SRC emacs-lisp
372
(setq neo-theme 'ascii)
373
#+END_SRC
375
** Hide permissions and owners to make file lists less noisy [[http://ergoemacs.org/emacs/file_management.html][(from Xah Lee's blog)]]
376
#+BEGIN_SRC emacs-lisp
377
(add-hook 'dired-mode-hook
378
(lambda ()
379
(dired-hide-details-mode 1)))
382
#+BEGIN_SRC emacs-lisp
389
(setq browse-url-browser-function 'browse-url-default-macosx-browser)
391
** Enable cookies
392
#+BEGIN_SRC emacs-lisp
393
(setq w3m-use-cookies t)
395
396
* Auto completion
397
#+BEGIN_SRC emacs-lisp
398
(add-hook 'prog-mode-hook 'company-mode)
399
(setq company-tooltip-align-annotations t)
400
#+END_SRC
401
404
From [[http://stackoverflow.com/questions/3417438/closing-all-other-buffers-in-emacs][StackOverflow]]
406
(defun close-all-buffers ()
407
(interactive)
408
(mapc 'kill-buffer (buffer-list)))
410
** Reload files
411
#+BEGIN_SRC emacs-lisp
412
(defun revert-all-buffers ()
413
(interactive)
414
(dolist (buf (buffer-list))
415
(with-current-buffer buf
416
(when (buffer-file-name)
417
(revert-buffer t t t)))))
418
#+END_SRC
419
420
* Desaturate
421
#+BEGIN_SRC emacs-lisp
422
(defun desaturate-color (color-hex)
423
"Converts a color string to its desaturated equivalent hex string"
427
(append (apply
428
'color-hsl-to-rgb
429
(apply
430
'color-desaturate-hsl
431
`(,@(apply 'color-rgb-to-hsl (color-name-to-rgb color-hex)) 100)))
432
'(2))))
434
(defun transform-theme-colors (fn)
435
"Apply FN to the colors on every active face.
436
437
FN should accept the face symbol and the current color,
438
and return the new color to be applied."
439
(interactive)
440
(mapc
441
(lambda (face)
442
(mapc
443
(lambda (attr)
444
(let ((current (face-attribute face attr)))
445
(unless (or (not current)
446
(listp current)
449
(set-face-attribute face nil attr (funcall fn face current)))))
455
(current (if (listp full) (member :color full))))
462
463
(defun desaturate-theme ()
464
"As title: desaturate all currently active face colorsj."
465
(interactive)
466
(transform-theme-colors
467
(lambda (face color)
468
(desaturate-color color))))
469
470
(defun invert-theme ()
471
"Take the complement of all currently active colors."
472
(interactive)
473
(require 'color)
474
(transform-theme-colors
475
(lambda (face color)
476
(apply
477
'color-rgb-to-hex
478
(color-complement color))))
479
(let ((current-ns-appearance (assoc 'ns-appearance default-frame-alist)))
480
(cond ((eq (cdr current-ns-appearance) 'light)
481
(setf (cdr current-ns-appearance) 'dark))
482
((eq (cdr current-ns-appearance) 'dark)
483
(setf (cdr current-ns-appearance) 'light)))))
484
#+END_SRC
485
* Mode Line
486
#+BEGIN_SRC emacs-lisp
487
(setq mode-line-format
488
(list
489
"%& %b%n"
490
" ~ "
491
"%m"
492
" ~ "
493
"%l:%c"))