summaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/init.el
blob: b7bd392631de7823b45874e19495e97c3ac20409 (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
;; --- FUNCTIONS ---
(defun load-if-exists (filename)
  (when (file-exists-p filename) (load-file filename)))

(defun bab/disable-line-numbers (&optional dummy dummy2)
  (display-line-numbers-mode -1))

(defun bab/sidebar-toggle ()
  "Toggle both `dired-sidebar' and `ibuffer-sidebar'."
  (interactive)
  (dired-sidebar-toggle-sidebar)
  (ibuffer-sidebar-toggle-sidebar))

;; --- BUG WORKAROUNDS ---

;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341
;; Affects ability to use the gnu package repository on gnutls 3.6.
;; Should recheck when emacs >26 is out.
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")

;; https://stackoverflow.com/questions/26108655/
;; https://lists.gnu.org/archive/html/bug-gnu-emacs/2014-12/msg00781.html
;; Apparently the gnu package repository has had unverifiable
;; signatures since 2014 and nobody cares ¯\_(ツ)_/¯
(setq package-check-signature nil)

;; --- TERMINAL SUPPORT ---
(add-to-list 'term-file-aliases '("st-256color" . "tmux-256color"))

;; --- PACKAGE REPOSITORIES ---
(require 'package)
(setq package-archives
    '(("gnu"   . "https://elpa.gnu.org/packages/")
      ("melpa" . "https://melpa.org/packages/")))

(package-initialize)

(require 'use-package)

(require 'whitespace)
(require 'yasnippet)
(require 'evil)

;; --- GLOBAL MODES ---
(evil-mode 1)               ;; Make emacs usable
(global-hl-line-mode 1)     ;; Highlight the line containing the cursor
(show-paren-mode 1)         ;; Highlight matching parenthesis

(use-package ivy
  :config
  (setq ivy-use-virtual-buffers t
        enable-recursive-minibuffers t)
  (ivy-mode 1))

(use-package flycheck
  :ensure t
  :config
  (add-to-list 'display-buffer-alist
               `(,(rx bos "*Flycheck errors*" eos)
                 (display-buffer-reuse-window
                  display-buffer-in-side-window)
                 (side            . bottom)
                 (reusable-frames . visible)
                 (window-height   . 0.33)))
  :init
  (global-flycheck-mode))

;; --- ORG MODE ---
(use-package org-ql
  :demand t
  :mode
  (("\\.org$" . org-mode))
  :init
  (add-to-list 'auto-mode-alist `(,(expand-file-name "~/org/") . org-mode))
  :bind
  (("C-c a" . org-agenda))
  :hook
  (org-agenda-finalize . bab/disable-line-numbers)
  :config
  (org-super-agenda-mode 1)
  (load-file "~/.emacs.d/org-mode.el"))

(use-package calfw-org
  :demand t)

;; --- PROJECTS ---
(use-package projectile
  :demand t
  :config
  (setq projectile-completion-system 'ivy)
  (projectile-mode 1)
  :bind-keymap
  ("C-c p" . projectile-command-map))

(use-package counsel-projectile
  :config (counsel-projectile-mode 1)
  :after (ivy projectile))

;; --- WINDOW MANAGEMENT ---
(windmove-default-keybindings 'control)
(use-package windswap
  :init
  (windswap-default-keybindings 'control 'shift))

;; --- GIT INTEGRATION ---
(use-package magit
  :commands
  (magit-status)
  :bind
  (("<f12>" . magit-status))
  :hook
  (magit-status-mode . bab/disable-line-numbers))

;; --- FILE TREE / BUFFER LIST ---
(use-package projectile-speedbar
  :bind
  ("<f8>" . projectile-speedbar-toggle)
  :hook
  (speedbar-mode . bab/disable-line-numbers))

;; --- AUTO-COMPLETE ---
(use-package company
  :config
  (global-company-mode)
  (require 'color)
  (let ((bg "midnight blue"))
    (set-face-attribute 'company-tooltip      nil :background bg)
    (set-face-attribute 'company-scrollbar-bg nil :background (color-lighten-name bg 20))
    (set-face-attribute 'company-scrollbar-fg nil :background (color-lighten-name bg 40)))
  )

(use-package company-posframe
  :after company
  :config
  (setq company-posframe-show-indicator nil
        company-posframe-quickhelp-delay nil)
  (company-posframe-mode 1)
  )

(use-package company-c-headers
  :after company
  :config (push 'company-c-headers company-backends))

(use-package company-lsp
  :after company
  :config (push 'company-lsp company-backends))

;; --- LANGUAGE SERVERS ---
(use-package lsp-mode
  :hook (typescript-mode . lsp-deferred)
  :config
  (add-to-list 'lsp-language-id-configuration '(zig-mode . "zig"))
  (lsp-register-client
   (make-lsp-client
    :new-connection (lsp-stdio-connection "/opt/zls/zls")
    :major-modes '(zig-mode)
    :server-id 'zls))
  :commands (lsp lsp-deferred))

(use-package lsp-ui
  :hook (lsp-mode . lsp-ui-mode))

(use-package company-lsp
  :commands company-lsp)

;; --- AUTO-FORMAT ON SAVE ---
(use-package prettier-js
  :config
  (setq prettier-js-args
        '("--trailing-comma" "all"
          "--use-tabs" "true"
          "--print-width" "110"
          "--arrow-parens" "avoid"
          "--end-of-line" "auto"))
  :hook (typescript-mode . prettier-js-mode))

;; --- THEME ---
(use-package doom-themes
  :config
  (setq doom-themes-enable-bold t
        doom-themes-enable-italic t)
  (load-theme 'doom-palenight t)
  (doom-themes-visual-bell-config)
  (doom-themes-neotree-config)
  (doom-themes-org-config))

;; --- TODO ---
;;(require 'undo-tree)

;; --- POWERLINE ---
(require 'telephone-line)
(telephone-line-mode 1)

;; --- WHITESPACE ---
;; Show whitespace for prog-mode, but not other modes
(define-global-minor-mode bab/global-whitespace-mode whitespace-mode
  (lambda () (when (derived-mode-p 'prog-mode) (whitespace-mode))))
(bab/global-whitespace-mode 1)

;; --- INDENTATION ---
;; Two callable functions for enabling/disabling tabs in Emacs
(defun disable-tabs () (setq indent-tabs-mode nil))
(defun enable-tabs  ()
  (local-set-key (kbd "TAB") 'tab-to-tab-stop)
  (setq indent-tabs-mode t))

;; Hooks to Enable Tabs
(add-hook 'prog-mode-hook 'enable-tabs)
;; Hooks to Disable Tabs
;; Using tabs in lisp just leads to mixing tabs and spaces, which is yucky
(add-hook 'lisp-mode-hook 'disable-tabs)
(add-hook 'emacs-lisp-mode-hook 'disable-tabs)
(add-hook 'zig-mode-hook 'disable-tabs)

;; --- GENERAL PREFERENCES ---
(setq-default
 ;; --- THEME CONFIGURATION ---
 ;;dracula-enlarge-headings nil

 ;; -- TABS AND INDENTATION --
 ;; Set tab stops to every four spaces
 tab-width 4
 ;; Tab key indents if cursor at start of line, otherwise inserts tab character
 tab-always-indent nil
 ;; Backspace deletes one whole tab character
 backward-delete-char-untabify-method nil

 ;; --- MOUSE ---
 ;; Don't speed up during continued mouse wheel scrolling
 mouse-wheel-progressive-speed nil

 ;; -- C LANGUAGE --
 ;; Overall tab and brace placement style
 c-default-style "linux"
 ;; Indent width
 c-basic-offset 4

 ;; -- LISP --
 inferior-lisp-program "sbcl"

 ;; -- WHITESPACE --
 ;; Clean up trailing whitespace automatically on save
 whitespace-action '(auto-cleanup)
 ;; Configure what to highlight.
 ;; Main difference from default is that for overlong lines,
 ;; we only highlight the overlong tail, not the whole line
 whitespace-style
    '(face trailing tabs spaces lines-tail empty indentation space-after-tab
      space-before-tab space-mark tab-mark)

 ;; -- MISC --
 ;; Display line numbers, relative to the current line
 display-line-numbers 'relative
 ;; Don't show the emacs startup screen
 inhibit-startup-screen t
 )

(let ((fg "RoyalBlue4")
      (bg 'unspecified)
      (faces '(whitespace-hspace whitespace-newline whitespace-space whitespace-tab)))
  (dolist (face faces)
    (set-face-attribute face nil :foreground fg :background bg)))

(load-if-exists "~/.emacs.d/local.el")

(setq custom-file "~/.emacs.d/custom.el")
(load-file custom-file)