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
|
;;; -*- lexical-binding: t; -*-
;; fish as default confuses some sub processes of emacs
(setq shell-file-name (executable-find "bash"))
(setq ;; doom-font (font-spec :family "Hasklig" :size 15)
doom-unicode-font (font-spec :family "Julia Mono"))
;; (load-theme 'doom-palenight t)
(load-theme 'doom-moonlight t)
;; icons in the tray
(setq display-time-24hr-format 1)
(display-time-mode)
(display-battery-mode)
;; company-mode auto-completion, to turn off use :company-complete
(require 'company)
(setq company-idle-delay 0.2
company-minimum-prefix-length 3)
;; for some reason these were broken by default
(setq org-roam-capture-templates
'(("d" "default" plain "" :target
(file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}")
:unnarrowed t)))
(after! org
(setq org-todo-keywords
'((sequence "TODO" "PROGRESS" "IDEA" "WAITING" "QUESTION" "IDLE" "|" "DONE" "DISCARDED" "AWAITED")
(sequence "[ ](T)" "[X](D)"))
org-todo-keyword-faces
'(("[-]" . +org-todo-active)
("[?]" . +org-todo-onhold)
("KILL" . +org-todo-cancel))))
(after! org-special-block-extras
; center a single-line string in a block of width
(defun prooftree--center-string (width str)
(-let* ((padding (- width (length str)))
(half (/ padding 2))
(other (- padding half)))
(s-concat (s-repeat half " ")
(if (eq str nil) "" str)
(s-repeat other " "))))
;; helper
(defun join-stuff (w1 lines1 lines2)
(if (and (eq nil (car lines1)) (eq nil (car lines2)))
""
(-let ((previous (join-stuff w1 (cdr lines1) (cdr lines2))))
(s-concat previous (if (equal previous "") "" "\n")
(car lines1) (s-repeat (- w1 (length (car lines1))) " ")
(car lines2)))))
;; join two proof trees line-wise, with some spacing in between
(defun prooftree--linewise-join (tree1 tree2)
(-let* (((w1 . str1) tree1)
((w2 . str2) tree2)
(lines1 (reverse (s-split "\n" str1)))
(lines2 (reverse (s-split "\n" str2)))
(spacing (if (< (+ w1 w2) 4) 2 4)))
`(,(+ w1 spacing w2) . ,(join-stuff (+ spacing w1) lines1 lines2))))
;; join two proof trees line-wise, without any spacing
(defun prooftree--linewise-block-join (tree1 tree2)
(-let* (((w1 . str1) tree1)
((w2 . str2) tree2)
(lines1 (reverse (s-split "\n" str1)))
(lines2 (reverse (s-split "\n" str2))))
`(,(+ w1 w2) . ,(join-stuff w1 lines1 lines2))))
;; center a proof tree in a block of width
(defun prooftree--center-tree (width tree)
(-let* (((w . _) tree)
(padding (/ (- width w) 2)))
(prooftree--linewise-block-join `(,padding . "") tree)
))
;; prooftree--linewise-join, but for arbitrarily many proof trees in a list
(defun prooftree--join-trees (trees)
(if (equal (length trees) 1) (car trees)
(prooftree--join-trees `(,(prooftree--linewise-join (car trees) (cadr trees)) . ,(cddr trees)))))
;; produce readable plain text representations of proof trees
(defun org--list-to-plaintext-tree (lst)
(cond
((symbolp lst) '(0 . ""))
((symbolp (car lst)) (org--list-to-plaintext-tree (cadr lst)))
(t
(-let* (((conclusionâ‚€ children) lst)
((name named?) (s-split " :: " conclusionâ‚€))
(conclusion (or named? conclusionâ‚€)))
(if (not children)
(-let ((rendered (if named? (format "%s(%s)\n%s" (s-repeat (length conclusion) "-") name conclusion) conclusion))
(width (if named? (+ (length conclusion) 2 (length name)) (length conclusion))))
`(,width . ,rendered))
(-let* ((premises (cdr (mapcar #'org--list-to-plaintext-tree children)))
(premises-width (+ (* 4 (- (length premises) 1)) (apply '+ (mapcar #'car premises))))
(width (+ 2 (max premises-width (length conclusion)))))
`(,width .
,(format "%s\n%s%s\n%s"
(cdr (prooftree--center-tree width (prooftree--join-trees premises)))
(s-repeat width "-")
(if named? (format "(%s)" name) "")
(prooftree--center-string width conclusion)))))))))
;; same as the "tree" block, but with more than just LaTeX
(org-defblock prooftree (main-arg)
(let ((proof (cdr (with-temp-buffer
(org-mode) ; otherwise org-list-to-lisp is unhappy
(insert raw-contents)
(goto-char (point-min))
(org-list-to-lisp)))))
(pcase backend
(`latex (s-join "" (--map (format "\\[%s\\]" (org--list-to-math it)) proof)))
(_ (format "<pre>%s</pre>"
(s-join "\n\n" (--map (format "%s" (cdr (org--list-to-plaintext-tree it))) proof)))))))
)
(setq org-agenda-files '("~/org" "~/org/roam"))
(setq org-roam-directory "~/org/roam")
(setq org-roam-v2-ack t)
;; hooks to turn on lsp when entering haskell mode
;; TODO: not sure if necessary?
(add-hook 'haskell-mode-hook #'lsp)
(add-hook 'haskell-literate-mode-hook #'lsp)
;; mu4e is part of the mu system package, managed by nix
(add-to-list 'load-path "~/.nix-profile/share/emacs/site-lisp/mu4e/")
(after! mu4e
(set-email-account! "hacc"
'( (user-mail-address . "stuebinm@hacc.space")
(user-full-name . "stuebinm")
(m4u-maildir . "~/Maildir/hacc")
(mu4e-sent-folder . "/hacc/Sent")
(mu4e-trash-folder . "/hacc/Trash") )
t)
(set-email-account! "disroot"
'( (user-mail-address . "stuebinm@disroot.org")
(user-full-name . "terru")
(m4u-maildir . "~/Maildir/disroot")
(mu4e-sent-folder . "/disroot/Sent")
(mu4e-trash-folder . "/disroot/Trash"))
t)
(set-email-account! "tum"
'( (user-mail-address . "stuebinm@in.tum.de")
(user-full-name . "stuebinm")
(m4u-maildir . "~/Maildir/tum")
(mu4e-sent-folder . "/tum/Sent")
(mu4e-trash-folder . "/tum/Trash"))
t)
(set-email-account! "ilztalbahn"
'( (user-mail-address . "stuebinm@ilztalbahn.eu")
(user-full-name . "terru")
(m4u-maildir . "~/Maildir/ilztalbahn")
(mu4e-sent-folder . "/ilztalbahn/Sent")
(mu4e-trash-folder . "/ilztalbahn/Trash"))
t)
(setq sendmail-program (executable-find "msmtp")
send-mail-function #'smtpmail-send-it
message-sendmail-f-is-evil t
message-sendmail-extra-arguments '("--read-envelope-from")
message-send-mail-function #'message-send-mail-with-sendmail)
(setq mu4e-split-view 'vertical)
(setq mu4e-headers-visible-columns 80)
; initial search query ("/" by default, which makes fuzzy search annoying)
(setq mu4e-maildir-initial-input ""))
(after! helm-dictionary
(setq helm-dictionary-database
'(("de-en" . "~/org/dict/de-en.txt")
("es-de" . "~/org/dict/es-de.txt")
("en-it" . "~/org/dict/en-it-enwiktionary.txt")
("it-en" . "~/org/dict/it-en-enwiktionary.txt"))))
;; hide all these annoying popups that clutter the view
(setq lsp-ui-doc-enable nil)
(setq lsp-ui-sideline-show-code-actions nil)
(setq lsp-signature-render-documentation nil)
(after! forester-ts-mode
(setq treesit-font-lock-level 5)
(unless (treesit-ready-p 'forester)
(treesit-install-language-grammar 'forester))
(add-to-list 'auto-mode-alist '("\\.tree\\'" . forester-ts-mode)))
(after! (lsp-ui helm-lsp)
(lsp-signature-activate)
(add-to-list 'lsp-language-id-configuration
'(forester-ts-mode . "forester"))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection '("forester" "lsp"))
:major-modes '(forester-ts-mode)
:activation-fn (lsp-activate-on "forester")
:server-id 'forester))
;; custom version which will not blindly apply a single code action
;; if only one is available without asking about it first.
;; Source taken from https://github.com/emacs-lsp/helm-lsp/blob/master/helm-lsp.el
(lsp-make-interactive-code-action wingman-fill-hole "refactor.wingman.fillHole")
(lsp-make-interactive-code-action wingman-case-split "refactor.wingman.caseSplit")
(lsp-make-interactive-code-action wingman-refine "refactor.wingman.refine")
(lsp-make-interactive-code-action wingman-split-func-args "refactor.wingman.spltFuncArgs")
(lsp-make-interactive-code-action wingman-use-constructor "refactor.wingman.useConstructor")
(map! :map haskell-mode-map
"C-c s" #'lsp-wingman-split
"C-c h" #'lsp-wingman-fillhole)
(defun helm-lsp-code-actions-custom()
"Show lsp code actions using helm."
(interactive)
(let ((actions (lsp-code-actions-at-point)))
(cond
((seq-empty-p actions) (signal 'lsp-no-code-actions nil))
(t (helm :sources
(helm-build-sync-source
"Code Actions"
:candidates actions
:candidate-transformer
(lambda (candidates)
(-map
(-lambda ((candidate &as
&CodeAction :title))
(list title :data candidate))
candidates))
:action '(("Execute code action" . (lambda(candidate)
(print "selected code action")
(print (plist-get candidate :data))
(lsp-execute-code-action (plist-get candidate :data)))))))))))
(map! :map doom-leader-code-map
"a" #'helm-lsp-code-actions-custom))
|