-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.el
303 lines (262 loc) · 9.46 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
;; -*- lexical-binding: t; -*-
;; The default is 800 kilobytes. Measured in bytes.
(setq gc-cons-threshold (* 50 1000 1000))
(defun efs/display-startup-time ()
(message "Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done))
(add-hook 'emacs-startup-hook #'efs/display-startup-time)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setf
straight-vc-git-default-protocol 'https
straight-use-package-by-default t
use-package-verbose t
use-package-always-demand t)
(setq package-archives
'(("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("elpa" . "https://elpa.gnu.org/packages/")))
(use-package emacs
:config
(load-theme 'modus-vivendi)
(defun crm-indicator (args)
(cons (format "[CRM%s] %s"
(replace-regexp-in-string
"\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
crm-separator)
(car args))
(cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
(setq inhibit-startup-message t)
(scroll-bar-mode -1) ; Disable visible scrollbar
(tool-bar-mode -1) ; Disable the toolbar
(tooltip-mode -1) ; Disable tooltips
(set-fringe-mode 8)
(menu-bar-mode -1) ; Disable the menu bar
(setq visible-bell t)
(blink-cursor-mode -1)
(column-number-mode)
;; (setf display-line-numbers-type 'relative)
(global-display-line-numbers-mode t)
;; Disable line numbers for some modes
(dolist (mode '(org-mode-hook
term-mode-hook
shell-mode-hook
treemacs-mode-hook
eshell-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
(setq use-dialog-box nil)
(defalias 'yes-or-no-p 'y-or-n-p)
(setq create-lockfiles nil)
;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
(setq inhibit-startup-message t
initial-scratch-message "")
;;; Show matching parenthesis
(show-paren-mode 1)
;;; By default, there’s a small delay before showing a matching parenthesis. Set
;;; it to 0 to deactivate.
(setq show-paren-delay 0)
(setq show-paren-when-point-inside-paren t)
(setq show-paren-style 'parenthesis)
;;; Electric Pairs to auto-complete () [] {} "" etc. It works on regions.
(electric-pair-mode)
(setq redisplay-skip-fontification-on-input t
fast-but-imprecise-scrolling t)
(global-so-long-mode 1)
(setq async-shell-command-buffer 'new-buffer)
(defun path-slug (dir)
"Returns the initials of `dir`s path,
with the last part appended fully
Example:
(path-slug \"/foo/bar/hello\")
=> \"f/b/hello\" "
(let* ((path (replace-regexp-in-string "\\." "" dir))
(path (split-string path "/" t))
(path-s (mapconcat
(lambda (it)
(cl-subseq it 0 1))
(nbutlast (copy-sequence path) 1)
"/"))
(path-s (concat
path-s
"/"
(car (last path)))))
path-s))
(defun mm/put-command-in-async-buff-name (f &rest args)
(let* ((path-s (path-slug default-directory))
(command (car args))
(buffname (concat path-s " " command))
(shell-command-buffer-name-async
(format
"*async-shell-command %s*"
(string-trim
(substring buffname 0 (min (length buffname) 50))))))
(apply f args)))
(advice-add 'shell-command :around #'mm/put-command-in-async-buff-name)
(add-hook 'comint-mode-hook
(defun mm/do-hack-dir-locals (&rest _)
(hack-dir-local-variables-non-file-buffer)))
(advice-add #'start-process-shell-command :before #'mm/do-hack-dir-locals)
(advice-add 'compile :filter-args
(defun mm/always-use-comint-for-compile (args) `(,(car args) t)))
:bind ("<f5>" . modus-themes-toggle))
(use-package mood-line
:straight (:host github :repo "benjamin-asdf/mood-line")
:config
(setf mood-line-show-cursor-point t)
(mood-line-mode))
(use-package vertico
:init
(vertico-mode)
(setq vertico-scroll-margin 0)
(setq vertico-count 20)
(setq vertico-cycle t))
(use-package savehist :init (savehist-mode))
(use-package orderless
:init
(setq
completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides '((file (styles partial-completion)))))
(require 'dired)
;; https://github.com/Gavinok/emacs.d
(use-package consult
:ensure t
:bind (("C-x b" . consult-buffer)
("C-x C-k C-k" . consult-kmacro)
("M-y" . consult-yank-pop)
("M-g g" . consult-goto-line)
("M-g M-g" . consult-goto-line)
("M-g f" . consult-flymake)
("M-g i" . consult-imenu)
("M-s l" . consult-line)
("M-s L" . consult-line-multi)
("M-s u" . consult-focus-lines)
("M-s g" . consult-grep)
("M-s M-g" . consult-grep)
("C-x C-SPC" . consult-global-mark)
("C-x M-:" . consult-complex-command)
("C-c n" . consult-org-agenda)
:map dired-mode-map
("O" . consult-file-externally)
:map help-map
("a" . consult-apropos)
:map minibuffer-local-map
("M-r" . consult-history))
:custom
(completion-in-region-function #'consult-completion-in-region)
:config
(recentf-mode t))
(use-package marginalia
:ensure t
:config
(marginalia-mode))
(use-package embark-consult
:ensure t
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;; https://github.com/oantolin/embark
(use-package embark
:ensure t
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("C-;" . embark-dwim) ;; good alternative: M-.
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:init
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
:config
;; Hide the mode line of the Embark live/completions buffers
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
(use-package bash-completion
:init
(autoload 'bash-completion-dynamic-complete
"bash-completion"
"BASH completion hook")
(add-hook 'shell-dynamic-complete-functions
#'bash-completion-dynamic-complete)
:config
(defun bash-completion-capf-1 (bol)
(bash-completion-dynamic-complete-nocomint (funcall bol) (point) t))
(defun bash-completion-eshell-capf ()
(bash-completion-capf-1 (lambda () (save-excursion (eshell-bol) (point)))))
(defun bash-completion-capf ()
(bash-completion-capf-1 #'point-at-bol))
(add-hook
'sh-mode-hook
(defun mm/add-bash-completion ()
(add-hook 'completion-at-point-functions #'bash-completion-capf nil t))))
(use-package cider
:config
(setq cider-babashka-parameters "nrepl-server 0"
clojure-toplevel-inside-comment-form t)
(cider-register-cljs-repl-type 'nbb-or-scittle-or-joyride "(+ 1 2 3)")
(defun mm/cider-connected-hook ()
(when (eq 'nbb-or-scittle-or-joyride cider-cljs-repl-type)
(setq-local cider-show-error-buffer nil)
(cider-set-repl-type 'cljs)))
(add-hook 'cider-connected-hook #'mm/cider-connected-hook)
(defun simple-easy-clojure-hello ()
(interactive)
(unless
(executable-find "clj")
(user-error
"Install clojure first! browsing to %s"
(let ((url "https://clojure.org/guides/install_clojure")) (browse-url url) url)))
(let*
((dir (expand-file-name "simple-easy-clojure-hello" (temporary-file-directory)))
(_ (make-directory dir t))
(default-directory dir))
(shell-command "echo '{}' > deps.edn")
(make-directory "src" t)
(find-file "src/hello.clj")
(when (eq (point-min) (point-max))
(insert "(ns hello)\n\n(defn main []\n (println \"hello world\"))\n\n\n;; this is a Rich comment, use it to try out pieces of code while you develop.\n(comment\n (def rand-num (rand-int 10))\n (println \"Here is the secret number: \" rand-num))"))
(call-interactively #'cider-jack-in-clj)))
;; this is a simpler cider complete that
;; that does everything I need together with orderless.
;; also complete locals
(defun mm/cider-complete-at-point ()
"Complete the symbol at point."
(when (and (cider-connected-p)
(not (cider-in-string-p)))
(when-let*
((bounds
(bounds-of-thing-at-point
'symbol))
(beg (car bounds))
(end (cdr bounds))
(completion
(append
(cider-complete
(buffer-substring beg end))
(get-text-property (point) 'cider-locals))))
(list
beg
end
(completion-table-dynamic
(lambda (_) completion))
:annotation-function #'cider-annotate-symbol))))
(advice-add 'cider-complete-at-point :override #'mm/cider-complete-at-point))