blob: 72a1d1b0c2d6f4d6f1a0a323becf7f3042275d5c (
plain) (
blame)
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
#+TITLE: Emacs Configuration
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="file:///home/jason/.emacs.d/contrib/org-export.css" />
#+OPTIONS: html-style:nil
* Startup
** Defaults
#+BEGIN_SRC emacs-lisp
(setq
;; Hide the default startup screen
inhibit-startup-screen t
;; Define where to store recovery files
backup-directory-alist '(("." . "~/.emacs.d/backups"))
;; Use version numbers for backups.
version-control t
;; Number of newest versions to keep.
kept-new-versions 10
;; Number of oldest versions to keep.
kept-old-versions 0
;; Don't ask to delete excess backup versions.
delete-old-versions -1
;; Copy all files, don't rename them.
backup-by-copying t
;; Make backups files under version control.
vc-make-backup-files t
;; Don't confirm following when opening a symlink
vc-follow-symlinks t)
;; Save minibuffer command history
(savehist-mode +1)
(setq savehist-save-minibuffer-history +1
savehist-file "~/.emacs.d/savehist")
(setq savehist-additional-variables
'(kill-ring
search-ring
regexp-search-ring))
;; Automatically close parens when opening them
(electric-pair-mode 1)
;; Show matched parens
(show-paren-mode t)
;; Let y and n be good enough for yes and no questions
(fset 'yes-or-no-p 'y-or-n-p)
;; Auto-refresh files changed on the file system
(global-auto-revert-mode 1)
#+END_SRC
Use UTF-8 as the default encoding
#+BEGIN_SRC emacs-lisp
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)
#+END_SRC
I primarily use OSes that favor unix line endings, but occasionally I use
Windows. This forces the buffers to be utf-8 with unix line endings by default.
#+BEGIN_SRC emacs-lisp
(setq default-buffer-file-coding-system 'utf-8-unix)
#+END_SRC
Transient-mark-mode makes a region active only when it is highlighted.
Delete-selection-mode allows you to overwrite regions with what you're typing,
pasting, etc. This mimics the behavior of other editors.
#+BEGIN_SRC emacs-lisp
(transient-mark-mode 1)
(delete-selection-mode 1)
#+END_SRC
Trim trailing whitespace in my all of my files. If it turns out there is a
filetype that should include trailing whitespace I will whitelist it.
#+BEGIN_SRC emacs-lisp
(add-hook 'write-file-hooks
'(lambda ()
(delete-trailing-whitespace)))
#+END_SRC
** Look and Feel
#+BEGIN_SRC emacs-lisp
;; Hide the toolbar
(tool-bar-mode -1)
;; Hide the scrollbar
(scroll-bar-mode -1)
;; no beep
(setq ring-bell-function 'ignore
visible-bell nil)
;; display the full file path in the titlebar
(setq frame-title-format
(list (format "%s %%S: %%j " (system-name))
'(buffer-file-name "%f" (dired-directory dired-directory "%b"))))
#+END_SRC
Start Emacs full screen by default.
#+BEGIN_SRC emacs-lisp
(toggle-frame-maximized)
#+END_SRC
Winner mode tracks your window layouts so you can cycle between them with
=C-c <left-arrow>= and =C-c <right-arrow>=. It is extra handy when some other
mode ruins your current window layout.
#+BEGIN_SRC emacs-lisp
(winner-mode 1)
#+END_SRC
** Local Elisp Code
Add directories where I store elisp code to the load path
#+BEGIN_SRC emacs-lisp
(add-to-list 'load-path "~/.emacs.d/local-lib/")
#+END_SRC
Include my custom functions
#+BEGIN_SRC emacs-lisp
(require 'zzq-funcs)
#+END_SRC
Usernames and passwords are stored in a non-published file
#+BEGIN_SRC emacs-lisp
(load "~/.emacs.d/secrets" t)
#+END_SRC
** Keybindings
By default Emacs binds ~C-x k~ to ~kill-buffer~ which asks for the buffer you
want to close. 99.9% of the time I want to kill the buffer that is active so
make that the default behavior
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-x k") 'kill-this-buffer)
#+END_SRC
~ibuffer~ is a better buffer list utility so redefine the default buffer list
to it.
#+BEGIN_SRC emacs-lisp
;; Use ibuffer for the buffer list
(global-set-key (kbd "C-x C-b") 'ibuffer)
#+END_SRC
* Package Initalization
Define the package repositories
#+BEGIN_SRC emacs-lisp
(setq package-archives '(
("elpa" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
;; melpa builds git repositories and can be unstable
("melpa" . "http://melpa.org/packages/")
;; marmalade has version uploaded by the maintainers
;; ("marmalade" . "https://marmalade-repo.org/packages/")
;; melpa-stable builds from git tags but may be missing dependencies
;; ("melpa-stable" . "https://stable.melpa.org/packages/")
))
(package-initialize)
#+END_SRC
I use jweigly's [[https://github.com/jwiegley/use-package][use-package]] to manage packages so it needs to be installed.
#+BEGIN_SRC emacs-lisp
;; Packages are managed by the use-package package, so we need to make sure it's installed
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
;; slight optimization for use-package's :bind directive
(require 'bind-key)
#+END_SRC
* Themes
[[https://github.com/synic/jbeans-emacs][jbeans]] is a jellybeans.vim clone maintained by synic
#+BEGIN_SRC emacs-lisp
(require 'jbeans-theme)
(load-theme 'jbeans t)
#+END_SRC
* Auto-completion
I use [[https://company-mode.github.io/][company-mode]] for autocompletion.
#+BEGIN_SRC emacs-lisp
(use-package company
:ensure t
:init
(setq
;; Display the suggestion popup quickly
company-idle-delay 0.4
;; Display the suggestion popup after 1 character
company-minimum-prefix-length 1)
:config
(add-hook 'company-mode-hook '(lambda ()
(progn
;; I prefer to use TAB instead of RETURN to finish completion
(define-key company-active-map [return] nil)
(define-key company-active-map [tab] 'company-complete-selection)))))
#+END_SRC
[[https://github.com/expez/company-quickhelp][Company-quickhelp]] displays documentation in a popup next to the match list
#+BEGIN_SRC emacs-lisp
(use-package company-quickhelp
:ensure t
:config
(add-hook 'company-mode-hook '(lambda ()
(progn
(company-quickhelp-mode)))))
#+END_SRC
* Version Control
Use [[https://magit.vc/][magit]] to supplement emacs built in version control system
#+BEGIN_SRC emacs-lisp
(use-package magit
:ensure t
:commands (magit-status magit-blame magit-log-buffer-file)
:bind (("C-c v s" . magit-status)
("C-c v B" . magit-blame)
("C-c v L" . magit-log-buffer-file)))
#+END_SRC
* Packages
** Paradox
[[https://github.com/Malabarba/paradox/][Paradox]] is a better emacs package manager.
#+BEGIN_SRC emacs-lisp
(use-package paradox
:ensure t
:config
(paradox-enable))
#+END_SRC
** avy
[[https://github.com/abo-abo/avy][avy]] is a quick way to jump around buffers
#+BEGIN_SRC emacs-lisp
(use-package avy
:ensure t
:bind (("C-:" . avy-goto-line)))
#+END_SRC
** which-key
[[https://github.com/justbur/emacs-which-key][which-key]] displays a pop up with key binding hints as you press them
#+BEGIN_SRC emacs-lisp
(use-package which-key
:ensure t
:diminish which-key-mode
:init
(setq which-key-special-keys nil
which-key-use-C-h-commands t
which-key-echo-keystrokes 0.02
which-key-max-description-length 32
which-key-sort-order 'which-key-key-order-alpha)
:config
(which-key-mode))
#+END_SRC
** ivy/swiper
[[https://github.com/abo-abo/swiper][Ivy]], swiper, and counsel are a framework for autocompleting emacs things
#+BEGIN_SRC emacs-lisp
(use-package ivy
:ensure t
:pin elpa
:diminish ivy-mode
:bind (("C-s" . swiper)
("M-x" . counsel-M-x)
("C-x C-f" . counsel-find-file))
:init
(setq
;; Remove the ^ prefix
ivy-initial-inputs-alist nil
;; Display recently opened files when switching buffers
ivy-use-virtual-buffers t
;; Use ivy for magit
magit-completing-read-function 'ivy-completing-read
;; Use ivy for projectile
projectile-completion-system 'ivy)
:config
(ivy-mode 1))
#+END_SRC
** persp-mode
[[https://github.com/Bad-ptr/persp-mode.el][persp-mode]] enables "workspaces" within Emacs. This is similar to how a window
manager might have several desktops
#+BEGIN_SRC emacs-lisp
(use-package persp-mode
:ensure t
:bind (([f8] . persp-switch))
:init
(setq persp-nil-name "Home"
persp-auto-resume-time 0)
;; Adding this so that capturing process is not interrupted with annoying
;; prompts "Kill and Close" etc.
(setq persp-kill-foreign-buffer-action nil
;; increase the default name length
persp-lighter '(:eval (format (propertize " #%.10s"
'face (let ((persp (get-current-persp)))
(if persp
(if (persp-contain-buffer-p (current-buffer) persp)
'persp-face-lighter-default
'persp-face-lighter-buffer-not-in-persp)
'persp-face-lighter-nil-persp)))
(safe-persp-name (get-current-persp)))))
:config
;; Set the persp-mode keymap prefix to <F9>, p
(persp-set-keymap-prefix (kbd "<f9> p"))
(persp-mode 1))
#+END_SRC
** powerline
[[https://github.com/milkypostman/powerline][powerline]] is a prettier mode line for emacs
#+BEGIN_SRC emacs-lisp
(use-package powerline
:ensure t
:init
(setq powerline-default-separator 'wave
powerline-display-mule-info nil)
:config
(powerline-default-theme))
#+END_SRC
** projectile
[[https://github.com/bbatsov/projectile][projectile]] adds some features around projects, for example finding only files
that are in the current project (defined by a .git directory).
#+BEGIN_SRC emacs-lisp
(use-package projectile
:ensure t
:diminish projectile-mode
:config
(projectile-global-mode))
#+END_SRC
** elfeed
[[https://github.com/skeeto/elfeed][Elfeed]] is an RSS reader for emacs
#+BEGIN_SRC emacs-lisp
(use-package elfeed
:ensure t
:bind (("<f9> f" . elfeed))
:init
(setq elfeed-db-directory "~/Shared/elfeeddb"))
#+END_SRC
[[https://github.com/remyhonig/elfeed-org][elfeed-org]] allows you to define your list of RSS feeds with an org
file instead of an elisp list.
#+BEGIN_SRC emacs-lisp
(use-package elfeed-org
:ensure t
:init
(setq rmh-elfeed-org-files (list "~/Shared/elfeed.org"))
:config
(elfeed-org))
#+END_SRC
[[https://github.com/algernon/elfeed-goodies][elfeed-goodies]] adds some ui/ux sugar to the elfeed screen
#+BEGIN_SRC emacs-lisp
(use-package elfeed-goodies
:ensure t
:config
(elfeed-goodies/setup))
#+END_SRC
** fill column indicator
FCI-mode draws a pretty little line on the right hand side indicating where the
fill column is.
#+BEGIN_SRC emacs-lisp
(use-package fill-column-indicator
:ensure t
:init
(setq
fci-rule-width 1
fci-rule-color "#202020")
:config
(add-hook 'prog-mode-hook 'fci-mode))
#+END_SRC
* Languages
** Python
Elpy does a great job of supporting Python so I just use that.
#+BEGIN_SRC emacs-lisp
(add-to-list 'package-archives
'("elpy" . "http://jorgenschaefer.github.io/packages/"))
(use-package elpy
:ensure t
:init
(setq elpy-rpc-project-specific t)
:config
(elpy-enable))
#+END_SRC
Enable some other modes when editing python files
#+BEGIN_SRC emacs-lisp
(add-hook 'python-mode-hook '(lambda ()
(setq-local fill-column 79)
(auto-fill-mode 1)))
#+END_SRC
** Rust
Installation:
- Install Rust: https://www.rust-lang.org/en-US/install.html
- Install Racer: https://github.com/racer-rust/racer
- Install the Rust source: =rustup component add rust-src= This goes to:
~/.multirust/toolchains/[toolchain]/lib/rustlib/src/rust/src
- Define the =RUST_SRC_PATH= environment var to the source directory
#+BEGIN_SRC emacs-lisp
(use-package rust-mode
:ensure t
:commands (rust-mode))
(use-package cargo
:ensure t
:commands (cargo-minor-mode))
(use-package racer
:ensure t
:commands (racer-mode))
(add-hook 'rust-mode-hook (lambda ()
(racer-mode)
(cargo-minor-mode)))
(add-hook 'racer-mode-hook #'company-mode)
#+END_SRC
* org-mode
** Setup
Start org-indent-mode. This displays a single indented star instead of many
stars in org-mode headings.
#+BEGIN_SRC emacs-lisp
(setq
;; Indents headers instead of displaying all of the asterisks
org-startup-indented t
;; Use emac's syntax highlighting for SRC block
org-src-fontify-natively t
;; Don't split the line when hitting M-RET for a new heading
org-M-RET-may-split-line '((item . nil)))
#+END_SRC
** Key Bindings
Define the keybindings for org-mode related things
| Key | Function | Description |
|-----+------------+-----------------------------|
| F12 | org-agenda | Display the org-agenda menu |
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f12>") 'org-agenda)
#+END_SRC
** Agenda
Rather than using ~C-[~ and ~C-]~ for adding files to the agenda manually this
defines directories that include all org files in the agenda.
#+BEGIN_SRC emacs-lisp
(setq org-agenda-files '("~/org/"))
#+END_SRC
** HTMLize
Styles source code blocks when exporting an org file to HTML
#+BEGIN_SRC emacs-lisp
(use-package htmlize
:ensure t)
#+END_SRC
|