summaryrefslogtreecommitdiff
path: root/emacs.d/init.el
blob: 16ddc916babf17bd0e2ac812a400624f3cc46547 (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
;;;; package -- Summary
;;;; Commentary:
;;; My Emacs init

;;; Code:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialise package system.

(require 'package)

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

(package-initialize)

;; Run this manually from time to time to update package lists.
;(package-refresh-contents)

;; use-package for easier configuration

(unless (package-installed-p 'use-package)
  (package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)

;; Put customization in its own file.
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Packages I like.

;; Major mode for editing Apache configuration files.
(use-package apache-mode)

;; Hide some mode line displays that are just noise.
(use-package diminish)

;; Major mode for GraphViz dot files.
(use-package graphviz-dot-mode)

;; Use git from Emacs.
(use-package magit
  :config
  (global-set-key (kbd "C-x g") 'magit-status))

;; Use the black Python source formatter to format Emacs buffers.
(use-package blacken)

;; Major mode for Python source code.
(use-package python-mode
  :config
  (py-underscore-word-syntax-p-off)
  (add-hook 'python-mode-hook 'blacken-mode))

;; Major mode for YAML files.
(use-package yaml-mode
  :config
  (add-to-list 'auto-mode-alist '("\\.rs\\'" . rustic-mode))
  (add-to-list 'auto-mode-alist '("\\.ick\\'" . yaml-mode))
  (add-to-list 'auto-mode-alist '("\\.vmdb\\'" . yaml-mode))
  (add-to-list 'auto-mode-alist '("\\.yaml\\'" . yaml-mode))
  (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))

;; Major mode for Markdown text files.
(use-package markdown-mode
  :config
  (add-to-list 'auto-mode-alist '("NEWS" . markdown-mode))
  (add-to-list 'auto-mode-alist '("README" . markdown-mode))
  (add-to-list 'auto-mode-alist '("\\.mdwn\\'" . markdown-mode)))

;; Major mode for formatting shell scripts.
(use-package shfmt
  :config
  (add-hook 'sh-mode-hook 'shfmt-on-save-mode))

;; Major mode for edit source code in the Rust language.
(use-package rustic
  :ensure
  :bind (:map rustic-mode-map
              ("M-j" . lsp-ui-imenu)
              ("M-?" . lsp-find-references)
              ("C-c C-c l" . flycheck-list-errors)
              ("C-c C-c a" . lsp-execute-code-action)
              ("C-c C-c r" . lsp-rename)
              ("C-c C-c q" . lsp-workspace-restart)
              ("C-c C-c Q" . lsp-workspace-shutdown)
              ("C-c C-c s" . lsp-rust-analyzer-status))
  :config
  ;; uncomment for less flashiness
  ;; (setq lsp-eldoc-hook nil)
  ;; (setq lsp-enable-symbol-highlighting nil)
  ;; (setq lsp-signature-auto-activate nil)

  ;; comment to disable rustfmt on save
  (setq rustic-format-on-save nil))

;; Mode for using the Rust Language Server Protocol for nicer Rust
;; editing.
(use-package lsp-mode
  :ensure
  :commands lsp
  :custom
  ;; what to use when checking on-save. "check" is default, I prefer clippy
  (lsp-rust-analyzer-cargo-watch-command "clippy")
  (lsp-eldoc-render-all t)
  (lsp-idle-delay 0.6)
  (lsp-rust-analyzer-server-display-inlay-hints t)
  :config
  (add-hook 'lsp-mode-hook 'lsp-ui-mode))

;; UI for lsp-mode.
(use-package lsp-ui
  :ensure
  :commands lsp-ui-mode
  :custom
  (lsp-ui-peek-always-show t)
  (lsp-ui-sideline-show-hover t)
  (lsp-ui-doc-enable nil))

;; Text completion framework for Emacs.
(use-package company
  :config
  (setq company-tooltip-align-annotations t))

;; Minor mode for on-the-fly checks for various types of files.
(use-package flycheck
  :config
  (setq-default flycheck-disabled-checkers '(python-pylint)))

;; Flycheck for the Rust language.
(use-package flycheck-rust)

;; Minor mode to color mode line based on how happy flycheck is.
(use-package flycheck-color-mode-line)
(eval-after-load 'flycheck
  '(add-hook 'flycheck-mode-hook 'flycheck-color-mode-line-mode))

;; UI theme for Emacs.
(use-package modus-operandi-theme
  :config
  (setq modus-operandi-theme-slanted-constructs t)
  (setq modus-operandi-theme-bold-constructs t)
  (load-theme 'modus-operandi t))

;; Show trailing whitespace.
(require 'whitespace)
(global-whitespace-mode t)
(setq whitespace-style '(face trailing))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; UI tweaks.

;; Use tab bar.
(tab-bar-mode)
(setq tab-bar-new-tab-to 'right)

;; Don't show help at startup
(setq inhibit-startup-screen t)

;; Disable tool bar in windows.
(tool-bar-mode 0)

;; Show column numbers in the mode line.
(column-number-mode t)
(setq column-number-indicator-zero-based nil)

;; Show line number before line.
(global-display-line-numbers-mode)
(set-face-attribute 'line-number nil
		    :height 0.8)
(set-face-attribute 'line-number-current-line nil
		    :foreground "#ff0000" :height 0.8)

;; Enable X CLIPBOARD selection, instead of PRIMARY.
(setq select-enable-clipboard t)

;; Show directories in the Buffers menu.
(setq buffers-menu-show-directories t)

;; Don't line wrap long lines.
(set-default 'truncate-lines t)

;; Show size in mode line.
;;(size-indication-mode)

;; Highlight current line.
(add-hook 'text-mode-hook 'hl-line-mode)
(add-hook 'prog-mode-hook 'hl-line-mode)

;; Key bindings
(global-set-key (kbd "<f5>") 'compile)
(global-set-key (kbd "C-<f5>") 'recompile)
(global-unset-key "\C-x\C-b")

(when (display-graphic-p)
  (global-unset-key "\C-x\C-c")
  (global-unset-key "\C-z")
  (global-unset-key "\C-_")
  (global-unset-key (kbd "\C-x\C-z"))
  (global-unset-key (kbd "<insert>"))
  (global-set-key (kbd "C-=") 'text-scale-adjust)
  (global-set-key (kbd "C-+") 'text-scale-adjust)
  (global-set-key (kbd "C--") 'text-scale-adjust)
  (global-set-key (kbd "C-0") 'text-scale-adjust)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Other tweaks.

;; Prevent Extraneous Tabs
(setq-default indent-tabs-mode nil)

;; Do not make backup files when saving.
(setq make-backup-files nil)

;; Turn on auto-fill-mode in all text modes automatically.
(setq text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))

;; Don't require double spaces to end sentences.
(setq sentence-end-double-space nil)

;; Base font size.
(set-face-attribute 'default nil
		    :height 130
		    :family "Hack")

;; Set default dictionary.
(setq ispell-dictionary "en_US")

;; Turn on flyspell spell checking.
(require 'flyspell)
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(set-face-attribute 'flyspell-incorrect nil
		    :foreground "#ff0000")


;; Turn on flycheck mode for program code.
(add-hook 'prog-mode-hook 'flycheck-mode)
(add-hook 'yaml-mode-hook 'flycheck-mode)
(add-hook 'markdown-mode-hook 'flycheck-mode)
(set-face-attribute 'flycheck-error nil
		    :weight 'bold
		    :underline "#ff0000"
		    :foreground "#ff0000")

;; Show current function.
(add-hook 'prog-mode-hook 'which-function-mode)

;; Show matching parens.
(add-hook 'text-mode-hook 'show-paren-mode)
(add-hook 'prog-mode-hook 'show-paren-mode)

;; Disable vc-mode: I prefer magit, and I only use git.
(setq vc-handled-backends nil)


(provide 'init)
;;; init.el ends here