blob: 4fc50a23e9db0029aeaea351c4c7528f112b48b4 (
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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
(use-package emacs
:ensure nil
:demand t
:bind
(("C-x i" . insert-char)
("M-z" . zap-to-char)
("<f10>" . toggle-input-method))
:config
;; Sentence size
(setq sentence-end-double-space nil)
;; Keyboard things
(setq default-input-method "cyrillic-yawerty")
(setq default-transient-input-method "cyrillic-yawerty"))
;; spell check
(use-package text-mode
:ensure nil
:hook
(text-mode . flyspell-mode))
;; Tab settings
(use-package emacs
:config
(setq tab-always-indent 'complete)
(setq tab-first-completion 'word-or-paren-or-punct)
(setq-default tab-width 4
indent-tabs-mode nil))
(use-package yasnippet
:ensure t
:hook ((LaTeX-mode . yas-minor-mode)
(post-self-insert . my/yas-try-expanding-auto-snippets))
:config
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
(yas-global-mode t)
(use-package warnings
:config
(cl-pushnew '(yasnippet backquote-change)
warning-suppress-types
:test 'equal))
(setq yas-triggers-in-field t)
;; Function that tries to autoexpand YaSnippets
;; The double quoting is NOT a typo!
(defun my/yas-try-expanding-auto-snippets ()
(when (and (boundp 'yas-minor-mode) yas-minor-mode)
(let ((yas-buffer-local-condition ''(require-snippet-condition . auto)))
(yas-expand)))))
(use-package yasnippet-capf
:ensure t
:after cape
:config
(add-to-list 'completion-at-point-functions #'yasnippet-capf))
(use-package cdlatex
:hook ((cdlatex-tab . yas-expand)
(cdlatex-tab . cdlatex-in-yas-field))
:config
(use-package yasnippet
:bind (:map yas-keymap
("<tab>" . yas-next-field-or-cdlatex)
("TAB" . yas-next-field-or-cdlatex))
:config
(defun cdlatex-in-yas-field ()
;; Check if we're at the end of the Yas field
(when-let* ((_ (overlayp yas--active-field-overlay))
(end (overlay-end yas--active-field-overlay)))
(if (>= (point) end)
;; Call yas-next-field if cdlatex can't expand here
(let ((s (thing-at-point 'sexp)))
(unless (and s (assoc (substring-no-properties s)
cdlatex-command-alist-comb))
(yas-next-field-or-maybe-expand)
t))
;; otherwise expand and jump to the correct location
(let (cdlatex-tab-hook minp)
(setq minp
(min (save-excursion (cdlatex-tab)
(point))
(overlay-end yas--active-field-overlay)))
(goto-char minp) t))))
(defun yas-next-field-or-cdlatex nil
(interactive)
"Jump to the next Yas field correctly with cdlatex active."
(if
(or (bound-and-true-p cdlatex-mode)
(bound-and-true-p org-cdlatex-mode))
(cdlatex-tab)
(yas-next-field-or-maybe-expand)))))
(use-package denote
:ensure t
:config
(require 'bard-writing)
(setq denote-directory "~/Notes/denote/")
(setq denote-buffer-name-prefix "[Note] "
denote-rename-buffer-format "%t %b")
(setq denote-known-keywords
'("emacs"
"linux"
"programming"
"org"
"school"
"language"
"history"
"biology"
))
(setq denote-templates
'((default . "Related to — ")
(todo . bard/denote-todo-template)))
(setq denote-save-buffers t)
(setq denote-prompts '(title keywords))
(setq denote-sort-dired-extra-prompts nil)
(setq denote-sort-dired-default-sort-component 'identifier)
(setq denote-sort-dired-default-reverse-sort nil)
;; backlinks sidebar
(setq denote-backlinks-display-buffer-action
'((display-buffer-in-direction)
(direction . right)
(window-width . 0.33)
(window-height . fit-window-to-buffer)
(dedicated . t)))
(denote-rename-buffer-mode 1)
(require 'bard-writing)
:hook
(dired-mode . denote-dired-mode)
:bind
(("C-c n n" . denote)
("C-c n d" . denote-sort-dired)
("C-c n r" . denote-rename-file-using-front-matter)
("C-c n k" . denote-rename-file-keywords)
("C-c n I" . denote-add-links)
("C-c n b" . bard/consult-buffer-notes) ; notes buffer
("C-c n B" . bard/ibuffer-notes) ; notes buffer but more
(:map dired-mode-map ; rename files in dired with denote structure
("r" . denote-rename-file))))
(use-package denote-org
:ensure t
)
(use-package denote-silo
:ensure t
:config
(setq denote-silo-directories '("~/Notes/denote"
"~/Notes/Old Notes/")))
(use-package denote-sequence
:ensure t
:config
(require 'bard-writing)
:bind
("C-c n N" . denote-sequence)
("C-c n D" . denote-sequence-dired))
(use-package denote-journal
:ensure t
:bind
("C-c n j" . denote-journal-new-or-existing-entry)
:config
(setq denote-journal-directory "~/Notes/denote/journal/")
(setq denote-journal-title-format "Daily Tasks and Notes"))
(use-package denote-roam
:ensure nil
:load-path "~/Code/denote-roam/"
:bind
("C-c n i" . denote-roam-insert-or-create-node) ; node insert
("C-c n o" . denote-roam-find-or-create-node) ; node open
:custom
(denote-roam-include-journal nil)
(denote-roam-directory "~/Notes/denote")
:config
(denote-roam-mode t))
(use-package org-roam
:ensure t
:custom
(org-roam-directory (file-truename "~/Notes/denote"))
:bind (("C-c n l" . org-roam-buffer-toggle))
:config
(cl-defmethod org-roam-node-type ((node org-roam-node))
"Return the TYPE of NODE based on its filetags."
(let ((tags (org-roam-node-tags node)))
(cond
((member "bib" tags) "reference")
((member "topic" tags) "topic")
(tags "main")
(t "root"))))
(setq org-roam-node-display-template
(concat "${type:10} ${title:*} " (propertize "${tags:*}" 'face 'org-tag)))
(setq org-roam-db-node-include-function
(lambda ()
(not (member "ATTACH" (org-get-tags)))))
(org-roam-db-autosync-mode 1))
(use-package org-roam-ui
:ensure t
:bind
("C-c n u" . org-roam-ui-open)
:custom
(org-roam-ui-open-on-start nil))
;; Center line scrolling for focused writing
(use-package emacs
:config
(define-minor-mode bard/scroll-center-cursor-mode
"Toggle centered cursor scrolling behavior."
:init-value nil
:lighter " S="
:global nil
(if bard/scroll-center-cursor-mode
(setq-local scroll-margin (* (frame-height) 2)
scroll-conservatively 0
maximum-scroll-margin 0.5)
(dolist (local '(scroll-preserve-screen-position
scroll-conservatively
maximum-scroll-margin
scroll-margin))
(kill-local-variable `,local))))
(defun bard/cursor-centered-p ()
"Check if `bard/scroll-center-cursor-mode` is currently active."
(bound-and-true-p bard/scroll-center-cursor-mode))
:bind
(("C-c L" . bard/scroll-center-cursor-mode)))
(use-package olivetti
:ensure t
:config
(setq olivetti-minimum-body-width 90)
(setq olivetti-recall-visual-line-mode-entry-state t)
:hook
((olivetti-mode-on . (lambda () (olivetti-set-width 90)))
))
;; narrowing and focus mode
(use-package logos
:ensure t
:config
(defun logos-reveal-entry ()
"Reveal Org or Outline entry."
(cond
((and (eq major-mode 'org-mode)
(org-at-heading-p))
(org-show-subtree))
((or (eq major-mode 'outline-mode)
(bound-and-true-p outline-minor-mode))
(outline-show-subtree))))
(setq logos-outlines-are-pages t)
(setq logos-outline-regexp-alist
`((emacs-lisp-mode . "^;;;+ ")
(org-mode . "^\\* +")
(t . ,(or outline-regexp logos--page-delimiter))))
(setq-default logos-hide-cursor nil
logos-hide-mode-line nil
logos-hide-header-line t
logos-hide-buffer-boundaries t
logos-hide-fringe t
logos-variable-pitch t
logos-olivetti t)
(defun bard/logos--recenter-top ()
"Use `recenter' to reposition the view at the top."
(unless (derived-mode-p 'prog-mode)
(recenter 1))) ; Use 0 for the absolute top
:hook
((logos-page-motion . bard/logos--recenter-top))
:hook
((org-mode . logos-focus-mode)
(markdown-mode . logos-focus-mode))
:bind
(("M-]" . logos-forward-page-dwim)
("M-[" . logos-backward-page-dwim)
("<f9>" . logos-focus-mode)
("C-x n n" . logos-narrow-dwim)))
(use-package typst-ts-mode
:ensure t
:hook (typst-ts-mode . eglot-ensure)
:config
(add-to-list 'treesit-language-source-alist
'(typst "https://github.com/uben0/tree-sitter-typst")))
;; Tinymist for LSP
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(typst-ts-mode "tinymist")))
(use-package typst-preview
:ensure t
:init
(setq typst-preview-autostart t)
(setq typst-preview-open-browser-automatically t)
:custom
(setq typst-preview-browser "zen"
typst-preview-invert-colors "never"
typst-preview-executable "tinymist"
typst-preview-partial-rendering t)
;; :config
;; (define-key typst-preview-mode-map (kbd "C-c C-j") 'typst-preview-send-position)
)
(use-package citar
:ensure t
:bind
("C-c n c" . citar-open)
:config
(setq citar-bibliography '("~/Documents/bib/references.bib"))
(setq org-cite-global-bibliography citar-bibliography
org-cite-insert-processor 'citar
org-cite-follow-processor 'citar
org-cite-activate-processor 'citar)
(setq citar-notes-paths '("~/Notes/denote"))
(setq citar-library-paths '("~/Documents/Research Articles/"))
;; (setq citar-file-open-functions 'find-file)
:hook
(org-mode . citar-capf-setup)
:bind (("C-c i" . citar-insert-citation)))
(use-package citar-denote
:ensure t
:config
(citar-denote-mode t)
)
(use-package citar-embark
:ensure t
)
(defun bard/create-bib-entry ()
(interactive)
(let* ((default-file (when (derived-mode-p 'dired-mode)
(dired-get-file-for-visit)))
(file (read-file-name "PDF: "
"~/Documents/Research Articles/"
default-file nil
(when default-file
(file-name-nondirectory default-file)))))
(find-file "~/Documents/bib/references.bib")
(goto-char (point-max))
(yas-expand-snippet
(format "@article{$1,
author = {$2},
title = {$3},
journaltitle = {$4},
year = {$5},
doi = {$9},
url = {$10},
file = {PDF:%s:application/pdf},
}" file))))
(use-package citar-typst
:ensure t
:hook (typst-ts-mode . citar-typst-mode))
(provide 'bard-emacs-writing)
|