aboutsummaryrefslogtreecommitdiffstats
path: root/config.org
blob: 44afa00c667a991a2a20b7e9ae83c25571caa54b (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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
#+TITLE: Emacs Configuration
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="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
      tab-width 4)
#+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

yasnippet's tab completion can conflict with term mode, so disable that

#+BEGIN_SRC emacs-lisp
(add-hook 'term-mode-hook (lambda()
			    (setq yas-dont-activate-functions t)))

#+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

I want to treat whitespace as a word when removing words because I end
up reformatting new lines and indents a lot (python doc strings).

#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<C-backspace>") 'maybe-backward-kill-word)
(global-set-key (kbd "<M-delete>") 'maybe-backward-kill-word)
(global-set-key (kbd "M-d") 'maybe-kill-word)
(global-set-key (kbd "<C-delete>") 'maybe-kill-word)
#+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
(use-package jbeans-theme
  :ensure t
  :config
  (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.1
   ;; 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
** Magit
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
** diff-hl
[[https://github.com/dgutov/diff-hl][diff-hl]] displays diff information in the margin

#+BEGIN_SRC emacs-lisp
(use-package diff-hl
  :ensure t
  :init
  (setq diff-hl-margin-mode t
        diff-hl-flydiff-mode t)
  :config
  (global-diff-hl-mode))
#+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
** expand-region
[[https://github.com/magnars/expand-region.el][expand-region]] will expand a region by meanigful units. For example if you have
the string ~"pony killer"~ and you move the cursor to the first p and hit the key
1 time it will highlight ~pony~, hit it a 2nd time it will highlight ~pony
killer~, and a 3rd time ~"pony killer"~ will be highlighted.

#+BEGIN_SRC emacs-lisp
(use-package expand-region
  :ensure t
  :bind ("C-=" . er/expand-region))
#+END_SRC
** dired
Dired is a file manager mode built in to emacs.

Dired-eXtra adds some additional functionality to dired
Features include:

- Omitting “uninteresting” files from Dired listings
- Dired local variables file (.dired)
- Shell command guessing
- "Virtual Dired" allows you to view directories based on command output
- Cleaning commands
- Dired current file and file at point commands (C-x C-j)

#+BEGIN_SRC emacs-lisp
(require 'dired-x)
#+END_SRC

Emacs' philosophy is to create a new buffer for new content. This makes sense
for an editor but a file manager usually reuses it's window as you browse the
file system. This reverts dired to that behavior, but doesn't fix it if you use
the mouse to click a directory or filename.

#+BEGIN_SRC emacs-lisp
(put 'dired-find-alternate-file 'disabled nil)
#+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
    ;; Allow the input to be selectable with C-P RET. Useful for creating files
    ivy-use-selectable-prompt t)
    :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-behaviour 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
  :bind-keymap
    ("C-c p" . projectile-command-map)
  :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/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
** editorconfig
Some of the project I work on use editorconfig to sync style guide
configurations across everyone's editors

#+BEGIN_SRC emacs-lisp
(use-package editorconfig
  :ensure t
  :config
  (editorconfig-mode 1))
#+END_SRC
** ag
ag is the silversearcher. It's faster than using grep

#+BEGIN_SRC emacs-lisp
(use-package ag
  :ensure t)
#+END_SRC
** restclient
[[https://github.com/pashky/restclient.el][restclient]] is a package that allows you to make raw HTTP queries to
websites and returns the response. It is much like the Postman chrome
plugin.

#+BEGIN_SRC emacs-lisp
(use-package restclient
  :ensure t
  :config
  (add-to-list 'auto-mode-alist '("\\.restclient" . restclient-mode)))
#+END_SRC
** yaml
[[https://github.com/yoshiki/yaml-mode][yaml-mode]] adds support for yaml config files

#+BEGIN_SRC emacs-lisp
(use-package yaml-mode
  :ensure t
  :config
  (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))
#+END_SRC
** helpful
[[https://github.com/Wilfred/helpful][helpful]] is an alternative to the built-in Emacs help that provides more
contextual information

#+BEGIN_SRC emacs-lisp
(use-package helpful
  :ensure t
  :bind (("C-h f" . helpful-callable)
         ("C-h v" . helpful-variable )
         ("C-h k" . helpful-key)))
#+END_SRC
* Languages
** prog-mode
Settings for all programming modes.
#+BEGIN_SRC emacs-lisp
(setq display-line-numbers-width 4)

(defun my-prog-mode-setup ()
  (display-line-numbers-mode))

(add-hook 'prog-mode-hook 'my-prog-mode-setup)
#+END_SRC
** flycheck
[[https://github.com/flycheck/flycheck][flycheck]] is an on-the-fly syntax checker for many languages.

#+BEGIN_SRC emacs-lisp
(use-package flycheck
  :ensure t
  :config
  (add-hook 'prog-mode-hook 'flycheck-mode))
#+END_SRC
** flyspell
flyspell is an on-the-fly spell checker
#+BEGIN_SRC emacs-lisp
(use-package flyspell
  :ensure t
  :config
  (add-hook 'prog-mode-hook 'flyspell-prog-mode))
#+END_SRC
** Python
[[https://github.com/proofit404/anaconda-mode][anaconda-mode]] has support for code navigation, docs, and completion for Python.

#+BEGIN_SRC emacs-lisp
(use-package anaconda-mode
  :ensure t)
(use-package company-anaconda
  :ensure t
  :config
  (eval-after-load "company"
   '(add-to-list 'company-backends '(company-anaconda :with company-capf))))
#+END_SRC

[[https://github.com/porterjamesj/virtualenvwrapper.el][virtualenvwrapper.el]] adds support for virtualenvs for emacs.

#+BEGIN_SRC emacs-lisp
(use-package virtualenvwrapper
  :ensure t
  :config
  (venv-initialize-interactive-shells)
  (venv-initialize-eshell))
#+END_SRC

This part is for setting up python mode in the way I prefer.

#+BEGIN_SRC emacs-lisp
(defun my-python-setup ()
  (anaconda-mode)
  (anaconda-eldoc-mode)
  (company-mode)
  (auto-fill-mode 1)
  (setq-local fill-column 79)
  (setq-local indent-tabs-mode nil))
(add-hook 'python-mode-hook 'my-python-setup)
#+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
** Go
The golang setup requires some additional packages:
#+BEGIN_SRC bash
# Code complete
go get -u github.com/nsf/gocode
# Finds symbols in the code
go get -u github.com/rogpeppe/godef
# Updates imports adding missing ones and removing unused ones
go get -u golang.org/x/tools/cmd/goimports
#+END_SRC

#+BEGIN_SRC emacs-lisp
(defun my-golang-setup ()
  (setq-local indent-tabs-mode t)
  (setq-local tab-width 4)
  ;;(go-eldoc-setup)
  (add-hook 'before-save-hook 'gofmt-before-save)
  (local-set-key (kbd "M-.") 'godef-jump)
  (local-set-key (kbd "M-*") 'pop-tag-mark)
  (local-set-key (kbd "C-c /") 'comment-or-uncomment-region))

(use-package go-mode
  :ensure t
  :commands (go-mode)
  :config
  (add-hook 'go-mode-hook 'my-golang-setup))

(use-package company-go
  :ensure t
  :config
  (add-hook 'go-mode-hook 'company-mode)
  (add-to-list 'company-backends 'company-go))
#+END_SRC
** Javascript/JSON
#+BEGIN_SRC emacs-lisp
(defun my-json-setup ()
  (make-local-variable 'js-indent-level)
  (setq js-indent-level 2))
(add-hook 'json-mode-hook
  (my-json-setup))
#+END_SRC
** API Blueprint
#+BEGIN_SRC emacs-lisp
(use-package apib-mode
  :ensure t
  :config
  (add-to-list 'auto-mode-alist '("\\.apib" . apib-mode)))
#+END_SRC
* org-mode
** Setup
#+BEGIN_SRC emacs-lisp
(setq org-directory "~/org"

  ;; 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 '((default . nil))

  ;; Define the default drawers
  org-drawers (quote ("PROPERTIES" "LOGBOOK"))

  ;; define some frequently used tags for the add tag menu
  org-tag-alist '(
                  ("project" . ?p)
                  ("@work" . ?w)
                  ("@home" . ?h)
                  ("eventmq" . ?q))


  ;; Define a default width for inline images. this can be overridden
  ;; by +ATTR_*: width="200"
  org-image-actual-width '(400)
)

(defun my-org-mode-setup ()
  (setq-local display-line-numbers-width 4))

(add-hook 'org-mode-hook 'my-org-mode-setup)

;; these extensions should be considered org-mode files
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org\.gpg\\|org_archive\\)$" . org-mode))

#+END_SRC
** Key Bindings
Define the keybindings for org-mode related things

| Key    | Function          | Description                         |
|--------+-------------------+-------------------------------------|
| F12    | org-agenda        | Display the org-agenda menu         |
| F9 c g | org-clock-goto    | Go to the current clocked task      |
| F9 c l | org-clock-in-last | Clock into the last clocked in task |
| F9 c o | org-clock-out     | Clock out of the current task       |
| C-c c  | org-capture       | Display the org-capture menu        |

#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f12>") 'org-agenda)
(global-set-key (kbd "<f9> c g") 'org-clock-goto)
(global-set-key (kbd "<f9> c l") 'org-clock-in-last)
(global-set-key (kbd "<f9> c o") 'org-clock-out)
(global-set-key (kbd "C-c c") 'counsel-org-capture)

#+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

Set up org capture. This feature lets me hit C-c c to quickly capture
information from any buffer.

#+BEGIN_SRC emacs-lisp
(setq
  ;; Define the default file for org-capture items
  org-default-notes-file "~/org/refile.org"

  ;; Define how many levels to display when refiling org items
  org-refile-targets (quote ((nil :maxlevel . 3)
                             (org-agenda-files :maxlevel . 3)))

  ;; Show the full org header path when displaying refile options
  org-refile-use-outline-path t

  ;; Allow refile to create parent nodes with confirmation
  org-refile-allow-creating-parent-nodes (quote confirm)

  ;; generate all possible refile paths so it's faster to search
  org-outline-path-complete-in-steps nil

  ;; Define the menu options for org-capture
  org-capture-templates (quote
                         (("t" "TODO" entry
                          (file+headline org-default-notes-file "Inbox")
                          "* TODO %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n")

                          ("T" "TODO w/ file location" entry
                           (file+headline org-default-notes-file "Inbox")
                           "* TODO %?\n:PROPERTIES:\n:CREATED: %U\n:LOCACTION: %a\n:END:\n%i")

                          ("i" "Interrupting Task" entry
                           (file+headline org-default-notes-file "Inbox")
                           "* Started %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n"
                           :clock-in :clock-resume)

                          ("e" "Emacs idea" entry
                           (file+headline "~/org/emacs.org" "Emacs")
                           "* TODO %^{Task}\n:PROPERTIES:\n:CREATED: %U\n:END:\n"
                           :immediate-finish t)

                          ("n" "note" entry (file org-default-notes-file)
                           "* %? :NOTE:\n:PROPERTIES:\n:CREATED: %U\n:END:\n%U\n%a\n")

                          ("j" "Journal" entry (file+datetree "~/org/diary.org.gpg")
                           "* %u\n%U\n"
                           :unnarrowed t)

                          ("w" "Web site" entry (file "~/Code/org/refile.org")
                           "* %a :website:\n:PROPERTIES:\n:CREATED: %U\n:END:\n%:initial")))


)
#+END_SRC

Set up org's TODO system

#+BEGIN_SRC emacs-lisp
(setq
  ;; Allows selecting capture method by pressing the letter in the parenthesis
  ;; after C-c C-t
  org-use-fast-todo-selection t

  ;; Define the default states for TODO items
  org-todo-keywords '((sequence "TODO(t)" "NEXT" "STARTED" "WAITING" "|" "DONE(d)" "DELEGATED(g)")
			  (sequence "|" "CANCELED"))

  ;; Define the colors for the TODO states
  org-todo-keyword-faces '(("NEXT" . "orange")
                           ("STARTED" . "dark yellow")
                           ("WAITING". "dark orange")
                           ("DELEGATED" . "light blue")
                           ("CANCELED" . "dark red"))

  ;; Block parent TODO items which have incomplete child TODO items from being
  ;; marked DONE
  org-enforce-todo-dependencies t

  ;; Block parent TODO items which have incomplete check boxes from being
  ;; marked DONE
  org-enforce-todo-checkbox-dependencies t

  ;; Log the time a TODO task is marked as DONE
  org-log-done 'time
)
#+END_SRC

org-mode has a built in time tracking system that I like to use.

#+BEGIN_SRC emacs-lisp
(setq
  ;; Put clock, state, and note entries into the LOGBOOK drawer
  org-clock-into-drawer t

  ;; Show a lot of clock history
  org-clock-history-length 23

  ;; Automatically clock-in if the clock is already open
  org-clock-in-resume t

  ;; Automatically clock out when a task is marked as done
  org-clock-out-when-done t

  ;; Quickly changing tasks will add a time of 0 to the log book. These aren't
  ;; very helpful so they should be removed
  org-clock-out-remove-zero-time-clocks t

  ;; save running clock and history when exiting and reopening Emacs
  org-clock-persist t

  ;; Don't prompt when resuming an active clock after close
  org-clock-persist-query-resume nil

  ;; enable autoresolution for open clocks
  org-clock-auto-clock-resolution 'when-no-clock-is-running

  ;; Include the current clocked in task in clock reports
  org-clock-report-include-clocking-task t

  ;; display a warning when idle for x minutes
  org-clock-idle-time 15

)
#+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