/
init.el
347 lines (300 loc) · 11 KB
/
init.el
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
;;; package --- Summary
;;; Commentary:
;; This is an Emacs init for all of my programming tasks.
;; The base requirement is package.el, which is included in the Emacs 24
;; distribution.
;; I'm old, so I need bigger fonts!
(set-face-attribute 'default nil
:height 150
)
;; no gnu splash screen on startup
(setq inhibit-splash-screen t)
;; empty message in the scratch buffer on startup
(setq initial-scratch-message "")
(setq inhibit-startup-message t)
;; opens a buffer on a new file without confirmation (seen in C-x C-f)
(setq confirm-nonexistent-file-or-buffer nil)
;; always kill the buffer on exit
;; seems to produce the same result as
;; (setq kill-buffer-query-functions nil)
(setq kill-buffer-query-functions
(remq 'process-kill-buffer-query-function
kill-buffer-query-functions))
;; always use spaces.
(setq-default indent-tabs-mode nil)
;; set apropos to search more broadly.
(setq apropos-do-all t)
;; don't add newline at the end of the visited file.
(setq mode-require-final-newline nil)
;; Backup file buffer settings.
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/.emacs.d/backups")) ; don't litter my fs
delete-old-versions t
kept-new-versions 20
kept-old-versions 0
version-control t) ; use versioned backups
;; No toolbar, no menu.
(when (fboundp 'tool-bar-mode) (tool-bar-mode 0))
(menu-bar-mode 0)
;; mode-line customization
;; Show line number and column number in the mode line.
(line-number-mode 1)
(column-number-mode 1)
;; display time.
(setq display-time-format "%Y-%m-%d %H:%M")
(display-time)
;; yes/no becomes y/n in any yes/no prompt.
(fset `yes-or-no-p 'y-or-n-p)
;; eshell customizations
(setq eshell-hist-ignoredups t
eshell-scroll-to-bottom-on-input t
eshell-history-size 1000
eshell-buffer-maximum-lines 5000
eshell-destroy-buffer-when-process-dies t)
;; ediff side by side
(setq ediff-split-window-function 'split-window-horizontally)
;; prefer splitting windows horizontally (along the vertical axis)
(setq split-width-threshold 79)
(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.
'(custom-enabled-themes '(modus-vivendi))
'(native-comp-async-report-warnings-errors nil)
'(org-agenda-files '("~/notes.org"))
'(package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")
("melpa" . "https://melpa.org/packages/")))
'(package-selected-packages
'(
auto-complete
company
company-irony
company-quickhelp
counsel
csv-mode
direnv
exec-path-from-shell
flycheck
flycheck-irony
gptel
irony-eldoc
js2-mode
magit
markdown-mode
multi-vterm
nix-mode
org-tree-slide
platformio-mode
popup
projectile
rust-mode
toml-mode
vterm
yaml-mode
yasnippet
yasnippet-snippets
web-mode
)))
;; dired-x file handling
(add-hook 'dired-load-hook
(lambda ()
(load "dired-x")
(setq dired-x-hands-off-my-keys nil)
))
;; Pulled from emacs wiki and modified a bit.
;; "C-c d" inserts a yyyy-mm-dd date.
(defun insert-date (prefix)
"Insert the current date.
ISO format with C-u prefix. mm-dd-yy with two C-u prefixes."
(interactive "P")
(let ((format (cond
((not prefix) "<%Y-%m-%d>")
((equal prefix '(4)) "%Y-%m-%d")
((equal prefix '(16)) "%d-%m-%Y"))))
(insert (format-time-string format))))
(global-set-key (kbd "C-c d") 'insert-date)
;; Similar to insert-date except that we add HH:MM:SS. Adjust the format
;; strings to taste. If you don't like seconds, remove the ":%S"
(defun insert-timestamp (prefix)
"Insert the current timestamp.
ISO format with C-u prefix. common broken format with two C-u prefixes."
(interactive "P")
(let ((format (cond
((not prefix) "<%Y-%m-%d %H:%M:%S>")
((equal prefix '(4)) "%Y-%m-%d %H:%M:%S")
((equal prefix '(16)) "%d-%m-%Y %H:%M:%S"))))
(insert (format-time-string format))))
(global-set-key (kbd "C-c t") 'insert-timestamp)
;; org-mode visual customizations
(setq org-hide-emphasis-markers t)
(setq org-fontify-whole-heading-line t)
(setq org-src-fontify-natively t)
(setq org-hide-leading-stars t)
(setq org-startup-truncated nil)
(setq org-confirm-babel-evaluate nil)
(add-hook 'org-mode-hook #'toggle-word-wrap)
;; org-mode global keys
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
;; babel languages
(org-babel-do-load-languages
'org-babel-load-languages
'((shell . t)
(R . t)
(python . t)))
;; Bind these files and file types to ruby
(add-to-list 'auto-mode-alist '("Gemfile" . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rake\\'" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.ru\\'" . ruby-mode))
;; term settings
;; no more ansiterm now that we have vterm
;;(global-set-key [f1] 'ansi-term)
;; kill process on terminal exit. scraped from echosa.github.io/blog/2012/06/06/improving-ansi-term/
(defadvice term-sentinel (around my-advice-term-sentinel (proc msg))
(if (memq (process-status proc) '(signal exit))
(let ((buffer (process-buffer proc)))
ad-do-it
(kill-buffer buffer))
ad-do-it))
(ad-activate 'term-sentinel)
;; C-y doesn't usually work in terminals. This should help.
(add-hook 'term-mode-hook (lambda ()
(define-key term-raw-map (kbd "C-y") 'term-paste)))
;; if it isn't in elpa, I dump it in lisp/
;; like avr-asm-flymake. Apparently, this add to load-path must
;; be done after all packages are installed as the load-path is
;; overwritten.
(add-to-list 'load-path "~/.emacs.d/lisp/")
;;
;; Try to do any work that doesn't require outside packages before this point.
;;
(require 'package)
(package-initialize)
(package-install-selected-packages)
;; It's inelegant but I want to pick up the path from shell when on
;; os x. apparently, due to a current bug there isn't a way to set
;; the path for gui apps.
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize))
;; vterm settings
(global-set-key [f1] 'multi-vterm)
(setq vterm-kill-buffer-on-exit t)
(setq vterm-max-scrollback 10000)
;; ivy completion
(require 'swiper)
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
(setq ivy-wrap t)
(global-set-key (kbd "C-s") 'swiper-isearch)
(global-set-key (kbd "C-r") 'swiper-isearch-backward)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "M-y") 'counsel-yank-pop)
(global-set-key (kbd "<f2> f") 'counsel-describe-function)
(global-set-key (kbd "<f2> v") 'counsel-describe-variable)
(global-set-key (kbd "<f2> l") 'counsel-find-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "<f2> j") 'counsel-set-variable)
(global-set-key (kbd "C-x b") 'ivy-switch-buffer)
(global-set-key (kbd "C-c v") 'ivy-push-view)
(global-set-key (kbd "C-c V") 'ivy-pop-view)
;; handle mixed html / programming language files
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.rhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
;; javascript
(add-to-list 'auto-mode-alist '("\\.json\\'" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;; if you don't want to warn on missing semicolons,
;; uncomment the following
;; (setq js2-strict-missing-semi-warning t)
;; flycheck syntax checkers for python. flycheck will chose flake8 over pylint
;; if both are defined.
;; (setq flycheck-python-flake8-executable "~/.virtualenvs/emacsenv/bin/flake8")
;; (setq flycheck-python-pylint-executable "~/.virtualenvs/emacsenv/bin/pylint")
;; (add-hook 'python-mode-hook #'(lambda () (setq flycheck-checker 'python-pylint)))
(require 'yasnippet)
;;(yas-global-mode 1)
(yas-reload-all)
(add-hook 'js2-mode-hook 'yas-minor-mode)
(add-hook 'python-mode-hook 'yas-minor-mode)
(add-hook 'ruby-mode-hook 'yas-minor-mode)
(add-hook 'c-mode-hook 'yas-minor-mode)
(require 'auto-complete-config)
(ac-config-default)
(setq ac-ignore-case nil)
(add-to-list 'ac-modes 'ruby-mode)
(add-to-list 'ac-modes 'web-mode)
;;(add-to-list 'ac-modes 'python-mode)
(require 'yaml-mode)
;; yaml-mode for salt files
(add-to-list 'auto-mode-alist '("\\.sls\\'" . yaml-mode))
;; rust and lsp
(add-hook 'rust-mode-hook #'cargo-minor-mode)
(add-hook 'toml-mode-hook #'cargo-minor-mode)
;; ensure rust-analyzer is installed. from the command line run:
;; rustup component add rust-analyzer
(add-hook 'rust-mode-hook 'eglot-ensure)
(require 'rust-mode)
(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
;; c/c++ and platformio
(require 'company)
(require 'platformio-mode)
(add-to-list 'company-backends 'company-irony)
(add-hook 'c++-mode-hook (lambda ()
(irony-mode)
(irony-eldoc)
(platformio-conditionally-enable)))
(add-hook 'c-mode-hook (lambda ()
(irony-mode)
(irony-eldoc)
(platformio-conditionally-enable)))
(add-hook 'irony-mode-hook
(lambda ()
(define-key irony-mode-map [remap completion-at-point]
'irony-completion-at-point-async)
(define-key irony-mode-map [remap complete-symbol]
'irony-completion-at-point-async)
(irony-cdb-autosetup-compile-options)))
(add-hook 'flyckeck-mode-hook 'flycheck-irony-setup)
;; set company globally.
(setq company-tooltip-align-annotations t)
;; Don't downcase suggestions.
(setq company-dabbrev-downcase nil)
(add-hook 'after-init-hook 'global-company-mode)
(company-quickhelp-mode 1)
;; projectile
(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
;; gptel
(require 'gptel)
(setq-default gptel-backend
(gptel-make-openai "llama-cpp"
:stream t
:protocol "http"
:host "localhost:8080"
:models '("local"))
gptel-model "test")
;; send to AI
(global-set-key (kbd "C-c g") 'gptel-send)
(provide 'init)
;;; init.el ends here
(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.
'(org-level-1 ((t (:inherit outline-1 :height 1.75))))
'(org-level-2 ((t (:inherit outline-2 :height 1.5))))
'(org-level-3 ((t (:inherit outline-3 :height 1.25))))
'(org-level-4 ((t (:inherit outline-4 :height 1.1)))))