aboutsummaryrefslogtreecommitdiffstats
path: root/doom/config.el
blob: 32b47c77baee383792b0bb70b35b182f521a1b48 (plain)
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
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-

;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!


;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets.
(setq user-full-name "Yann Herklotz"
      user-mail-address "yann@yannherklotz.com")

;; Doom exposes five (optional) variables for controlling fonts in Doom. Here
;; are the three important ones:
;;
;; + `doom-font'
;; + `doom-variable-pitch-font'
;; + `doom-big-font' -- used for `doom-big-font-mode'; use this for
;;   presentations or streaming.
;;
;; They all accept either a font-spec, font string ("Input Mono-12"), or xlfd
;; font string. You generally only need these two:
(setq doom-font (font-spec :family "Iosevka" :size 16)
      doom-variable-pitch-font (font-spec :family "Libre Baskerville")
      doom-serif-font (font-spec :family "Libre Baskerville"))

;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:
(setq doom-theme 'sanityinc-tomorrow-night)

;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/Dropbox/org/")

;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type nil)

;; Add some keybinding customisations.

;; Stop emacs from freezing when trying to minimize it on a tiling WM.
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "M-u")   #'upcase-dwim)
(global-set-key (kbd "M-l")   #'downcase-dwim)
(global-set-key (kbd "M-c")   #'capitalize-dwim)
(global-set-key (kbd "C-c z") #'quick-calc)
(global-set-key (kbd "<f5>")  #'revert-buffer)
(global-set-key (kbd "C-.")   #'other-window)
(global-set-key (kbd "C-,")   #'(lambda () (interactive) (other-window -1)))
(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c a") #'org-agenda)
(global-set-key (kbd "C-c c") #'org-capture)

;; Set undo-only correctly
(global-set-key (kbd "C-\\") 'undo-only)

;; Revert C-a and C-e to go to the beginning and end of line, not a fan of the
;; default smart functions.
(global-set-key (kbd "C-a") #'beginning-of-line)
(global-set-key (kbd "C-e") #'end-of-line)

;; Define functions to push and pop from mark.
(defun push-mark-no-activate ()
  "Pushes `point' to `mark-ring' and does not activate the region
   Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
  (interactive)
  (push-mark (point) t nil)
  (message "Pushed mark to ring"))

(defun jump-to-mark ()
  "Jumps to the local mark, respecting the `mark-ring' order.
  This is the same as using \\[set-mark-command] with the prefix argument."
  (interactive)
  (set-mark-command 1))

(global-set-key (kbd "C-`")   #'push-mark-no-activate)
(global-set-key (kbd "M-`")   #'jump-to-mark)

;; Delete an emacs client frame.
(defun y/exit-emacs-client ()
  "consistent exit emacsclient. If not in emacs client, echo a
  message in minibuffer, don't exit emacs. If in server mode and
  editing file, do C-x # server-edit else do C-x 5 0
  delete-frame"
  (interactive)
  (if server-buffer-clients
      (server-edit)
    (delete-frame)))

(global-set-key (kbd "C-c q") #'y/exit-emacs-client)

;; Swap two window positions.
(defun y/swap-windows ()
  "Swaps two windows and leaves the cursor in the original one"
  (interactive)
  (ace-swap-window)
  (aw-flip-window))

;; Define a custom key map for other useful commands.
(define-prefix-command 'y-map)
(global-set-key (kbd "C-c y") 'y-map)

(define-key y-map (kbd "s") 'y/swap-windows)
(define-key y-map (kbd "p") 'password-store-copy)
(define-key y-map (kbd "i") 'password-store-insert)
(define-key y-map (kbd "g") 'password-store-generate)
(define-key y-map (kbd "r") 'toggle-rot13-mode)

(defun y/insert-date ()
  "Insert a timestamp according to locale's date and time format."
  (interactive)
  (insert (format-time-string "%c" (current-time))))

(define-key y-map (kbd "d") 'y/insert-date)

;; Set backup directories into the tmp folder
(setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))

;; Automatically refresh files
(global-auto-revert-mode 1)
(setq auto-revert-verbose nil)

;; Remove automatic `auto-fill-mode', and replace it by `visual-line-mode',
;; which is a personal preference.
(remove-hook 'text-mode-hook #'auto-fill-mode)
(add-hook 'text-mode-hook #'+word-wrap-mode)

;; Set up magit when C-c g is called
(use-package! magit
  :bind (("C-x g" . magit-status)))

;; Configure activation for whitespace mode
(use-package! whitespace
  :bind (("C-x w" . whitespace-mode)))

;; Configure expand-region mode.
(use-package! expand-region
  :bind ("M-o" . er/expand-region))

;; Delete all whitespace until the first non-whitespace character.
(use-package! hungry-delete
  :config (global-hungry-delete-mode))

;; Org configuration
(use-package org
  :mode ("\\.org\\'" . org-mode)
  :init
  (map! :map org-mode-map
        "M-n" #'outline-next-visible-heading
        "M-p" #'outline-previous-visible-heading)
  (setq org-src-window-setup 'current-window
        org-return-follows-link t
        org-confirm-babel-evaluate nil
        org-use-speed-commands t
        org-structure-template-alist '(("a" . "export ascii")
                                       ("c" . "center")
                                       ("C" . "comment")
                                       ("e" . "example")
                                       ("E" . "export")
                                       ("h" . "export html")
                                       ("l" . "export latex")
                                       ("q" . "quote")
                                       ("s" . "src")
                                       ("v" . "verse")
                                       ("el" . "src emacs-lisp")
                                       ("d" . "definition")
                                       ("t" . "theorem"))))

(use-package! org-id
  :after org
  :init
  (setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id))

;; Disable org indent mode and remove C-, from the org-mode-map.
(after! org
  (setq org-startup-indented nil)
  (define-key org-mode-map (kbd "C-,") nil))

;; Set agenda files, refile targets and todo keywords.
(setq org-agenda-files (mapcar 'expand-file-name
                               (list "~/Dropbox/org/inbox.org"
                                     "~/Dropbox/org/main.org"
                                     "~/Dropbox/org/tickler.org"
                                     (format-time-string "~/Dropbox/org/journals/%Y-%m.org")))
      org-refile-targets `(("~/Dropbox/org/main.org" :maxlevel . 2)
                           ("~/Dropbox/org/someday.org" :level . 1)
                           ("~/Dropbox/org/tickler.org" :maxlevel . 2)
                           (,(format-time-string "~/Dropbox/org/journals/%Y-%m.org") :maxlevel . 2))
      org-todo-keywords '((sequence "TODO(t)" "WAITING(w)" "|" "DONE(d)" "CANCELLED(c)")))

;; Set custom agenda commands which can be activated in the agenda viewer.
(setq org-agenda-custom-commands
        '(("w" "At work" tags-todo "@work"
           ((org-agenda-overriding-header "Work")))
          ("h" "At home" tags-todo "@home"
           ((org-agenda-overriding-header "Home")))
          ("u" "At uni" tags-todo "@uni"
           ((org-agenda-overriding-header "University")))))

;; Set up org ref for PDFs
(use-package! org-ref
  :after org
  :bind (("C-c r" . org-ref-cite-hydra/body)
         ("C-c b" . org-ref-bibtex-hydra/body))
  :config
  (setq org-ref-bibliography-notes "~/Dropbox/bibliography/notes.org"
        org-ref-default-bibliography '("~/Dropbox/bibliography/references.bib")
        org-ref-pdf-directory "~/Dropbox/bibliography/papers/")
  (setq org-ref-completion-library 'org-ref-ivy-cite))

;; Set up org registers to quickly jump to files that I use often.
(set-register ?l (cons 'file "~/.emacs.d/loader.org"))
(set-register ?m (cons 'file "~/Dropbox/org/main.org"))
(set-register ?i (cons 'file "~/Dropbox/org/inbox.org"))
(set-register ?c (cons 'file (format-time-string "~/Dropbox/org/journals/%Y-%m.org")))

;; Set up dictionaries
(setq ispell-dictionary "en_GB")

(use-package! flyspell
  :config
  (define-key flyspell-mode-map (kbd "C-.") nil)
  (define-key flyspell-mode-map (kbd "C-,") nil))

;; Set up zettelkasten mode
(use-package! zettelkasten
  :config
  (zettelkasten-mode t))

;; Publishing projects, this one is for the zettelkasten
(use-package! ox-publish
  :config
  (setq org-publish-project-alist
        '(("zettelkasten"
           :base-directory "~/Dropbox/org/zettelkasten/"
           :base-extension "org"
           :publishing-directory "~/Dropbox/org/zettelkasten/html/"
           :publishing-function org-html-publish-to-html
           :headline-levels 4
           :auto-preamble t
           :with-toc nil
           :section-numbers nil
           :html-head "<link rel=\"stylesheet\" href=\"css/fonts.css\" />
<link rel=\"stylesheet\" href=\"css/default.css\" />"
           )))
  (add-hook 'org-export-before-processing-hook 'zettelkasten-org-export-preprocessor))

;; Mac configuration
(when (eq system-type 'darwin)
  (setq mac-right-option-modifier 'none
        mac-option-key-is-meta nil
        mac-command-key-is-meta t
        mac-command-modifier 'meta
        mac-option-modifier nil))

;; Here are some additional functions/macros that could help you configure Doom:
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package' for configuring packages
;; - `after!' for running code after a package has loaded
;; - `add-load-path!' for adding directories to the `load-path', relative to
;;   this file. Emacs searches the `load-path' when you load packages with
;;   `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c g k').
;; This will open documentation for it, including demos of how they are used.
;;
;; You can also try 'gd' (or 'C-c g d') to jump to their definition and see how
;; they are implemented.