summaryrefslogtreecommitdiff
path: root/emacs/init.el
blob: 0366c135bb0546f84d9eb88f60a1672c2b3ec849 (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
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
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ledger-reports
   (quote
    (("test" "ledger bal")
     ("bal" "%(binary) -f %(ledger-file) bal")
     ("reg" "%(binary) -f %(ledger-file) reg")
     ("payee" "%(binary) -f %(ledger-file) reg @%(payee)")
     ("account" "%(binary) -f %(ledger-file) reg %(account)"))))
 '(org-capture-templates
   (quote
    (("c" "Contact" entry
      (file "~/org/contacts.org")
      "* %(org-contacts-template-name)
:PROPERTIES:
:ADDRESS:
:EMAIL:
:PHONE:
:NOTE:
:END:" :empty-lines 0))))
 '(org-contacts-files (quote ("~/org/contacts.org")))
 '(package-selected-packages
   (quote
    (helm-projectile projectile notmuch which-key use-package spaceline smart-mode-line org-brain ivy helm-swoop helm-flyspell helm-bibtex flycheck exec-path-from-shell evil-ledger evil-leader company color-theme-sanityinc-tomorrow))))

;; Bootstrap `use-package'
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
                         ("melpa" . "https://melpa.org/packages/")))
(package-initialize)
(unless (package-installed-p 'use-package)
 (package-refresh-contents)
 (package-install 'use-package))

;; settings ---------------------------------------------------------------------------------------

(global-auto-revert-mode t)

(setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))

(setq make-backup-files nil)

;; packages ---------------------------------------------------------------------------------------

;; exec-path-from-shell
;; must be first as this populates environment variables
(use-package exec-path-from-shell
  :ensure t
  )
(exec-path-from-shell-initialize)

(load-file "~/source/dotfiles/emacs/undo-tree.el")
(require 'undo-tree)

;; company
(use-package company
  :ensure t
  )

;; evil
(use-package evil
  :config
  (evil-mode 1)
  (modify-syntax-entry ?_ "w")
)
(use-package evil-leader
  :ensure t
  :config
  (evil-leader/set-leader "<SPC>")
  (global-evil-leader-mode)
)

;; frames-only-mode
(use-package frames-only-mode
  :ensure t
)
(frames-only-mode)

;; flycheck
(use-package flycheck
  :ensure t
  :init (global-flycheck-mode))

;; helm
(use-package helm
  :ensure t
  :config
  (define-key helm-map (kbd "TAB") #'helm-execute-persistent-action)
  (define-key helm-map (kbd "<tab>") #'helm-execute-persistent-action)
  (define-key helm-map (kbd ":") #'helm-select-action)
  )
(use-package helm-flyspell
  :ensure t
  :init (flyspell-mode)
  )
(use-package helm-swoop
  :ensure t
  )
(use-package helm-bibtex
  :ensure t
  :init
  (setq bibtex-completion-bibliography '("~/literature/database.bib"))
  (setq bibtex-completion-library-path '("~/literature"))
  (setq bibtex-completion-notes-path "~/literature")
  (setq bibtex-completion-pdf-open-function
    (lambda (fpath)
      (call-process "evince" nil 0 nil fpath)
      )
    )
  )

;; ledger
(use-package ledger-mode
  :ensure t
  :mode "\\.ledger$"
  )
; TODO: consider using flycheck-ledger

;; org
(use-package org
  :ensure t
  )
(setq org-todo-keywords '((sequence "TODO" "WAITING" "|" "DONE" "DELEGATED" "CANCELED")))
(setq org-tags-column -99)
(setq org-id-track-globally t)
(setq org-id-locations-file "~/.emacs.d/.org-id-locations")
(setq org-brain-visualize-default-choices 'all)
(setq org-brain-title-max-length 12)
(setq org-agenda-files '("~/org/" "~/projects"))
(setq org-agenda-span 1)
(setq org-agenda-start-with-log-mode t)
(setq org-agenda-start-day "0d")
(setq org-agenda-window-setup 'only-window)
(setq org-clock-mode-line-total 'today)
(setq org-duration-format (quote h:mm))
(setq org-agenda-prefix-format '(
  (agenda  . "%i %-12.12:c %?-12t %s") ;; file name + org-agenda-entry-type
  (timeline  . "  % s")
  (todo  . " %i %-12:c")
  (tags  . " %i %-12:c")
  (search . " %i %-12:c")
  )
  )
(load "~/source/dotfiles/emacs/org-contacts.el")
(use-package org-contacts
  :ensure nil
  :after org
  :custom (org-contacts-files '("~/org/contacts.org"))
  )
(use-package org-capture
  :ensure nil
  :after org
  :preface
  (defvar my/org-contacts-template "* %(org-contacts-template-name)
:PROPERTIES:
:ADDRESS:
:EMAIL:
:PHONE:
:NOTE:
:END:" "Template for org-contacts.")
  :custom
  (org-capture-templates
   `(("c" "Contact" entry (file "~/org/contacts.org"),
      my/org-contacts-template
      :empty-lines 0))))

;; projectile
(use-package projectile
  :ensure t
)

;; spaceline
(use-package spaceline :ensure t)
(spaceline-compile
  ; left side
  '(
    (buffer-id :priority 99)
    (major-mode :priority 76)
    (version-control :when active :priority 75)
    (org-clock :when active :priority 99)
   )
  ; right side
  '(
    (line-column :priority 99)
    (buffer-position :priority 75)
    (buffer-size :priority 95)
   )
  )
(setq powerline-default-separator 'bar)
(spaceline-emacs-theme)
(spaceline-toggle-minor-modes-off)
(spaceline-toggle-buffer-encoding-abbrev-off)
(spaceline-compile)

;; which-key
(use-package which-key
  :ensure t
  :config
  (setq which-key-popup-type 'minibuffer)
  (setq which-key-allow-evil-operators t)
  )
(which-key-mode)

;;; theme -----------------------------------------------------------------------------------------

(menu-bar-mode -1)
(tool-bar-mode -1)
(toggle-scroll-bar -1)

(setq-default left-margin-width 0 right-margin-width 0)

(load-file "~/source/dotfiles/emacs/color-theme-tomorrow.el")
(color-theme-tomorrow-night)
(set-face-attribute 'highlight nil
  :background "#373b41"
  )
(set-face-attribute 'helm-selection nil
  :background "#373b41"
  :foreground "#c5c8c6"
  )
(set-face-attribute 'hl-line nil
  :background "#373b41"
  )
(set-face-attribute 'org-agenda-clocking nil
  :background "#373b41"
  :foreground "#8abeb7"
  :underline nil
  :inverse-video nil
  )
(global-hl-line-mode 1)
(setq mouse-highlight nil)

(add-to-list 'org-emphasis-alist
             '("*" (:background "#373b41"
		    :foreground "#c5c8c6"
		    )
               ))

;;; functions -------------------------------------------------------------------------------------

(defun flyspell-goto-previous-error (arg)
  "Go to arg previous spelling error."
  (interactive "p")
  (while (not (= 0 arg))
    (let ((pos (point))
          (min (point-min)))
      (if (and (eq (current-buffer) flyspell-old-buffer-error)
               (eq pos flyspell-old-pos-error))
          (progn
            (if (= flyspell-old-pos-error min)
                ;; goto beginning of buffer
                (progn
                  (message "Restarting from end of buffer")
                  (goto-char (point-max)))
              (backward-word 1))
            (setq pos (point))))
      ;; seek the next error
      (while (and (> pos min)
                  (let ((ovs (overlays-at pos))
                        (r '()))
                    (while (and (not r) (consp ovs))
                      (if (flyspell-overlay-p (car ovs))
                          (setq r t)
                        (setq ovs (cdr ovs))))
                    (not r)))
        (backward-word 1)
        (setq pos (point)))
      ;; save the current location for next invocation
      (setq arg (1- arg))
      (setq flyspell-old-pos-error pos)
      (setq flyspell-old-buffer-error (current-buffer))
      (goto-char pos)
      (if (= pos min)
          (progn
            (message "No more miss-spelled word!")
            (setq arg 0))))))

(defun check-previous-spelling-error ()
  "Jump to previous spelling error and correct it"
  (interactive)
  (push-mark-no-activate)
  (flyspell-goto-previous-error 1)
  (call-interactively 'helm-flyspell-correct))

(defun check-next-spelling-error ()
  "Jump to next spelling error and correct it"
  (interactive)
  (push-mark-no-activate)
  (flyspell-buffer)
  (flyspell-goto-next-error)
  (call-interactively 'helm-flyspell-correct))

(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"))

;;; hooks -----------------------------------------------------------------------------------------

;; text mode
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'text-mode-hook 'turn-on-visual-line-mode)

;; global
(add-hook 'after-init-hook 'global-company-mode)
(add-hook 'before-save-hook 'delete-trailing-whitespace)



;;; journaling ------------------------------------------------------------------------------------


(setq org-journal-dir "~/journal/")

(defun get-journal-file-today ()
  "Return filename for today's journal entry."
  (let ((daily-name (format-time-string "%Y-%m-%d.org")))
    (expand-file-name (concat org-journal-dir daily-name))))


(defun journal-file-today ()
  "Create and load a journal file based on today's date."
  (interactive)
  (copy-file "~/journal/template.org" (get-journal-file-today))
  (find-file (get-journal-file-today)))


;;; keybindings -----------------------------------------------------------------------------------



(org-babel-do-load-languages 'org-babel-load-languages
                             (append org-babel-load-languages
				     '((python     . t)
				       (ledger     . t)
				       (shell   .t)
                                (ruby       . t))))



(global-set-key "\t" 'company-complete-common)
(evil-leader/set-key "a" 'org-agenda-list)
(evil-leader/set-key "c" 'calc)
(evil-leader/set-key "f" 'helm-find-files)
(evil-leader/set-key "j" 'journal-file-today)
(evil-leader/set-key "k" 'kill-buffer)
(evil-leader/set-key "l" 'helm-bibtex)
(evil-leader/set-key "m" 'helm-mini)
(evil-leader/set-key "p" 'helm-projectile)
(evil-leader/set-key "q" 'save-buffers-kill-terminal)
(evil-leader/set-key "r" 'shell-command)
(evil-leader/set-key "s" 'check-next-spelling-error)
(evil-leader/set-key "t" 'org-clock-goto)
(evil-leader/set-key "T" 'org-clock-out)
(evil-leader/set-key "," 'other-window)
(evil-leader/set-key "/" 'helm-swoop)
(evil-leader/set-key "<SPC>" 'helm-M-x)
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )