-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.el
2023 lines (1790 loc) · 79.2 KB
/
config.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
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; -*- lexical-binding: t; -*-
;;; Commentary
;;
;; Generally speaking, this configuration is motivated
;; by the tenet of "be as lazy as possible" while
;; not causing any load order errors and accommodating
;; my fickle decision-making about which modules
;; and packages to have active in `init.el' and
;; `packages.el'. Hence, you'll likely find many `after!'
;; blocks that refer to packages that aren't currently installed
;; or toggled in
(doom-load-packages-incrementally '(org
magit
recentf
org-roam
org-capture
org-agenda
embark
consult))
;;; * Some functions
(after! emacs
(defun my/switch-buffer-other-window ()
(interactive)
(save-excursion
(consult-buffer-other-window))))
;;; * Basic emacs stuff
(defun EVA-02-p ()
(when (equal (system-name) "EVA-02") t))
(defun surfacep ()
(when (equal (system-name) "fedora") t))
(when (or (EVA-02-p) (surfacep))
(display-battery-mode))
(setq! display-time-format "%H:%M %d %b %Y")
(display-time-mode)
(when (EVA-02-p)
(setq! fancy-splash-image (expand-file-name "splash/you_will_never_be_happy-take-1.svg" doom-user-dir)))
;;; * Setup load path.
(or (equal (system-name) "pop-os") (surfacep))
(add-to-list 'load-path "~/.config/doom/")
(add-to-list 'load-path "~/.doom.d/")
(setq! local-package-path (expand-file-name "lisp/" doom-user-dir))
;;; * Buffer related config
;;; ** `activities'
;; (activities-mode)
;;; ** `dogears'
(setq! dogears-idle nil)
(dogears-mode)
(map!
:desc "Dogears save" "M-g M-s" #'dogears-remember
:desc "Dogears forward" "M-g M-f" #'dogears-forward
:desc "Dogears backward" "M-g M-b" #'dogears-back
:desc "Dogears list" "M-g M-l" #'dogears-list)
;;; ** `ace-window'
(when (modulep! :ui window-select)
(setq! aw-scope 'global))
(when (EVA-02-p)
(defun my/open-eat-other-frame ()
(interactive)
(let ((buf (eat)))
(switch-to-buffer (other-buffer buf))
(switch-to-buffer-other-frame buf))))
;;; ** `popper'
(after! popper
(setq! popper-reference-buffers
'("\\*Messages\\*"
"Output\\*$"
"\\*compilation\\*"
"\\*Async Shell Command\\*"
"\\*cider-repl.*?"
"\\*sly-description\\*"
"\\*Flycheck errors\\*"
"\\*Outline .*?\\*"
"\\*org-roam\\*"
pdf-outline-mode
help-mode
helpful-mode
compilation-mode))
(setq! popper-mode-line '(:eval (propertize " POP " 'face 'highlight))))
(popper-mode +1)
(popper-echo-mode)
;;; * Editing
(setq! kill-whole-line t)
(global-jinx-mode)
(defun my/find-bounds-of-regexps (open close)
(let ((start (point))
(parity 0)
(open-close (concat "\\(?:" open "\\|" close "\\)"))
end)
(save-excursion
(while (and (not (= parity -1))
(re-search-backward open-close nil t))
(if (looking-at open)
(setq parity (1- parity))
(setq parity (1+ parity))))
(setq end (point))
(goto-char start)
(while (and (not (= parity 0))
(re-search-forward open-close nil t))
(if (looking-back
close
(- (point) (length (match-string-no-properties 0))))
(setq parity (1+ parity))
(setq parity (1- parity))))
(when (= parity 0) (cons end (point))))))
;;; ** `easy-kill' and `expand-region' interop
(after! easy-kill
(defun easy-kill-expand-region ()
"Expand kill according to expand-region."
(interactive)
(let* ((thing (easy-kill-get nil))
(bounds (easy-kill--bounds)))
(save-mark-and-excursion
(set-mark (cdr bounds))
(goto-char (car bounds))
(er/expand-region 1)
(deactivate-mark)
(easy-kill-adjust-candidate thing (point) (mark)))))
(defun easy-kill-contract-region ()
"Expand kill according to expand-region."
(interactive)
(let* ((thing (easy-kill-get nil))
(bounds (easy-kill--bounds)))
(save-mark-and-excursion
(set-mark (cdr bounds))
(goto-char (car bounds))
(er/contract-region 1)
(deactivate-mark)
(easy-kill-adjust-candidate thing (point) (mark))))))
;;; ** Mark utilities
(defun push-mark-no-activate (&optional pt)
"Push `point' to local mark ring, without activating the region."
(interactive)
(push-mark (if pt
pt
(point)) t nil)
(message "Pushed point to mark ring"))
(defun jump-to-mark ()
"Jump to local mark, respecting `mark-ring' order."
(interactive)
(set-mark-command 1))
;;; ** Smartparens
(add-hook! prog-mode #'sp-use-smartparens-bindings)
;;; * Font config
(setq! variable-font "Iosevka Slab"
fixed-font (if (EVA-02-p)
"FiraMono Nerd Font"
"FiraCode")
variable-sans-serif "Iosevka Aile")
;;; ** Fontaine
(after! fontaine
(setq! fontaine-presets
`((regular-serif
:variable-pitch-family ,variable-font
:fixed-pitch-family ,fixed-font
:default-height 110
:default-weight light)
(regular-sans
:variable-pitch-family ,variable-sans-serif
:fixed-pitch-family ,fixed-font
:default-height 110
:default-weight light)
(office-monitor
:inherit regular-sans
:default-height 135)
(medium-serif
:inherit regular-serif
:default-height 140)
(medium-sans
:inherit regular-sans
:variable-pitch-weight light
:default-height 140)
(large-serif
:inherit medium-serif
:default-height 180)
(large-sans
:inherit medium-sans
:default-height 180)
(huge-serif
:inherit medium-serif
:default-height 210)
(huge-sans
:inherit medium-sans
:default-height 210)
(t ; our shared fallback properties
:fixed-pitch-family ,fixed-font
:fixed-pitch-height 1.0
:variable-pitch-family ,variable-font
:variable-pitch-weight regular
:variable-pitch-height 1.0
:fixed-pitch-serif-family ,fixed-font
:fixed-pitch-serif-weight nil
:fixed-pitch-serif-slant nil
:fixed-pitch-serif-height 1.0
:bold-family nil ; use whatever the underlying face has
:bold-weight bold
:italic-family nil
:italic-slant italic
:line-spacing nil))))
(fontaine-mode)
(fontaine-set-preset 'medium-sans)
(add-hook! enable-theme-functions #'fontaine-apply-current-preset)
(add-hook! text-mode #'variable-pitch-mode)
(remove-hook! text-mode #'display-line-numbers-mode)
;;; * LaTeX
(setq! TeX-engine 'xetex)
(after! math-delimiters
(setq! math-delimiters-compressed-display-math t))
(setq! bibtex-dialect 'biblatex)
;;; ** Helper functions
(use-package! latex-utils
:after (:and org latex)
:load-path local-package-path)
(after! (:or org latex)
(setq! cdlatex-use-dollar-to-ensure-math nil)
(defadvice! my/org-try-cdlatex-tab ()
"Try cdlatex tab when in `laas-mode'"
:override #'org-try-cdlatex-tab
(when laas-mode
(cond
;; Before any word on the line: No expansion possible.
((save-excursion (skip-chars-backward " \t") (bolp)) nil)
;; Just after first word on the line: Expand it. Make sure it
;; cannot happen on headlines, though.
((save-excursion
(skip-chars-backward "a-zA-Z0-9*")
(skip-chars-backward " \t")
(and (bolp) (not (org-at-heading-p))))
(cdlatex-tab) t)
((org-inside-LaTeX-fragment-p) (cdlatex-tab) t))))
(defun my/cdlatex-sub-superscript ()
"Insert ^{} or _{} unless the number of backslashes before point is odd.
When not in LaTeX math environment, _{} and ^{} will have dollars.
When pressed twice, make the sub/superscript roman."
(interactive)
(if (and nil
(equal this-command last-command))
(progn
(insert "\\mathrm{}")
(backward-char 1))
(if (cdlatex-number-of-backslashes-is-odd)
;; Quoted
(insert (event-basic-type last-command-event))
;; Check if we are in math mode, if not switch to or only add _ or ^
(if (not (or (laas-mathp)
cdlatex-sub-super-scripts-outside-math-mode))
(insert (event-basic-type last-command-event))
(cdlatex-ensure-math)
;; Insert the normal template.
(insert (event-basic-type last-command-event))
(insert "{}")
(forward-char -1))))))
(after! easy-kill
(add-to-list 'easy-kill-try-things 'sexp))
;;; ** laas-mode for auto expanding snippets
(add-hook! org-mode #'laas-mode)
(after! (:and laas (:or org latex))
(aas-set-snippets 'laas-mode
:cond #'laas-mathp
"opr" '(tempel "\\operatorname{" r "}" q)
"^" #'my/cdlatex-sub-superscript
"_" #'my/cdlatex-sub-superscript
"ox" "\\otimes"
"<=" "\\leqslant"
">=" "\\geqslant"
"iso" "\\cong"
"hom" "\\hom"
"ker" "\\ker"
"ZZ" "\\mathbb{Z}"
"CC" "\\mathbb{C}"
"RR" "\\mathbb{R}"
"*" "\\ast"
"QQ" "\\mathbb{Q}"))
;;; * eglot
(use-package! eglot-booster
:after eglot
:config
(eglot-booster-mode))
;;; * org-mode
(after! org
(plist-put org-latex-preview-appearance-options
:page-width 0.8)
(add-hook 'org-latex-preview-auto-ignored-commands 'next-line)
(add-hook 'org-latex-preview-auto-ignored-commands 'previous-line)
(setq! org-latex-preview-numbered t
org-latex-preview-live t))
;;; ** Variables
(add-hook! org-agenda-mode (setq-local line-spacing 0.35))
;;; *** `org-agenda' variables
(after! org
(setq! org-directory "~/Documents/org/"
org-default-notes-file "~/Documents/org/notes.org"
org-agenda-files '("~/Documents/org/inbox.org"
"~/Documents/org/gtd.org"
"~/Documents/org/tickler.org"
"~/Documents/org/graveyard.org"
"~/Documents/org/maybe.org"
"~/Documents/org/roam/daily/dailies.org")
org-refile-targets '((("~/Documents/org/gtd.org") :maxlevel . 2)
(("~/Documents/org/inbox.org") :maxlevel . 2)
(("~/Documents/org/tickler.org") :level . 1)
(("~/Documents/org/maybe.org") :level . 1)
(("~/Documents/org/notes.org") :maxlevel . 3)
(("~/Documents/org/research_notes.org") :maxlevel . 2)
(("~/Documents/org/graveyard.org") :level . 1)
(("~/Documents/org/roam/daily/dailies.org") :maxlevel . 5))
org-agenda-include-deadlines t
org-agenda-use-time-grid nil
org-agenda-block-separator nil
org-agenda-compact-blocks t
org-agenda-start-day nil ;; i.e. today
org-agenda-span 5
org-agenda-skip-scheduled-if-done t
org-agenda-skip-deadline-if-done t
org-agenda-todo-ignore-scheduled 'all
org-capture-templates '(("n" "Info/IDEA")
("nn" "Info node"
entry
(file "~/Documents/org/roam/roam.org")
"* %?\n:PROPERTIES:\n:ID: %(org-id-new)\n:CREATED: %(org-insert-time-stamp (current-time))\n:END:\n")
("nt" "Daily: Today"
entry
(file+olp+datetree "~/Documents/org/roam/daily/dailies.org")
"* %?\n:PROPERTIES:\n:ID: %(org-id-new)\n:END:\n"
:unnarrowed nil)
("ni" "Daily: Idea"
entry
(file+olp+datetree "~/Documents/org/roam/daily/dailies.org")
"* IDEA %? \n:PROPERTIES:\n:ID: %(org-id-new)\n:CREATED: %(org-insert-time-stamp (current-time))\n:END:\n")
("t" "Todo" entry (file "~/Documents/org/inbox.org")
"* TODO %?%i\n:PROPERTIES:\n:ID: %(org-id-new)\n:END:\n%a\n")
("r" "research" entry (file "~/Documents/org/inbox.org")
"* RSCH %?\n%i\n:PROPERTIES:\n:ID: %(org-id-new)\n:END:\n%a\n")
("i" "idea" entry (file "~/Documents/org/inbox.org")
"* IDEA %?\n%i\n%a\n")
("j" "Journal entry" entry (file+olp+datetree "~/Documents/org/journal.org")
;; Call with C-u C-u interactive argument to insert inactive stamp
"* %? \n%(funcall 'org-timestamp '(16) 't)"
:empty-lines 1)
("m" "Email workflow")
("mf" "Follow Up" entry (file "~/Documents/org/inbox.org")
"* TODO Follow up with %:fromname on %a :email:\n:PROPERTIES:\n:ID: %(org-id-new)\n:END:\n%i"
:immediate-finish t)
("mt" "Action Required" entry (file "~/Documents/org/inbox.org")
"* TODO %? \n:PROPERTIES:\n:REFERENCE: %a\n:END:\n%i")
("mr" "Read Later" entry (file"~/Documents/org/inbox.org")
"* TODO %:subject :email:\n%a\n:PROPERTIES:\n:ID: %(org-id-new)\n:END:\n%i"
:immediate-finish t))
org-refile-use-outline-path 'file))
;;; *** `org' variables
(after! org
(setq! org-outline-path-complete-in-steps nil
org-latex-src-block-backend 'engraved
org-use-speed-commands t
org-archive-location ".%s_archive::"
org-file-apps (quote
((auto-mode . emacs)
("\\.m\\'" . default)
("\\.?html?\\'" . /usr/bin/firefox)
("\\.pdf\\'" . emacs)))
org-export-with-drawers '(not "noex")
org-structure-template-alist '(("a" . "export ascii")
("c" . "center")
("C" . "comment")
("e" . "equation")
("E" . "export")
("h" . "export html")
("l" . "export latex")
("q" . "quote")
("s" . "src")
("v" . "verse"))
org-startup-with-latex-preview nil
org-todo-keywords '((sequence
"TODO(t)"
"IDEA(i)"
"EVENT(e)"
"WAIT(w)"
"PROG(g)"
"MAYBE(m)"
"DRAFT(D)"
"|"
"DONE(d)"
"CANCELLED(c)"))
org-attach-id-dir "~/Documents/org/.attach/"
org-latex-pdf-process (list "latexmk -f -pdf -%latex -shell-escape -interaction=nonstopmode -output-directory=%o %f")
org-latex-default-packages-alist '(("" "amssymb" t)
("" "amsmath" t ("lualatex" "xetex"))
("" "fontspec" t ("lualatex" "xetex"))
("AUTO" "inputenc" t ("pdflatex"))
("T1" "fontenc" t ("pdflatex")))
org-highlight-latex-and-related nil
org-startup-folded t
org-startup-with-inline-images nil
org-fontify-whole-heading-line t
org-fontify-done-headline t
org-fontify-quote-and-verse-blocks nil
org-ellipsis " "
org-image-actual-width 400
org-hide-emphasis-markers t))
(when (modulep! :app calendar)
(map! :map org-agenda-mode-map
:desc "Calendar" "C" #'=calendar))
;;; bibtex
(after! bibtex
(setq! bibtex-autokey-year-length 4
bibtex-autokey-name-year-separator "-"
bibtex-autokey-year-title-separator "-"
bibtex-autokey-titleword-separator "-"
bibtex-autokey-titlewords 2
bibtex-autokey-titlewords-stretch 1
bibtex-autokey-titleword-length 5))
;;; ** `ox-cv'
(use-package! ox-awesomecv
:after org)
;;; ** `org-present'
(after! org-present
(setq! org-present-hide-stars-in-headings t
org-present-text-scale 4.5)
(add-hook! org-present-mode
(setq-local visual-fill-column-mode 1)
(setq-local hl-line-mode nil)
(org-present-hide-cursor)
(org-display-inline-images)
(setq-local spell-fu-mode nil)
(hide-mode-line-mode))
(add-hook! org-present-mode-quit
(setq-local hl-line-mode 1)
(setq-local visual-fill-column-mode nil)
(org-present-show-cursor)
(setq-local spell-fu-mode 1)
(org-remove-inline-images)
(hide-mode-line-mode)))
;;; ** `org-super-agenda'
(after! org
(setq! org-agenda-custom-commands
'(("n" "Today's agenda"
((agenda "" ((org-super-agenda-groups
`((:discard (:file-path "graveyard"))
(:discard (:todo "MAYBE"))
(:name "Today"
:scheduled today
:face (:foreground ,(technicolor-get-color 'green) :extend t)
:order 2)
(:name "Due Today"
:face (:background ,(technicolor-relative-darken 'red 90) :extend t)
:deadline today
:order 1)
(:discard anything)))))
(alltodo ""
((org-agenda-overriding-header "")
(org-super-agenda-groups
`((:discard (:file-path "graveyard"))
(:discard (:file-path "maybe"))
(:discard (:todo "MAYBE"))
(:discard (:scheduled t))
(:discard (:deadline t))
(:name "To Process"
:todo ("EVENT" "TODO" "PROG" "WAIT")
:order 1
:face (:height 0.9
:foreground ,(technicolor-relative-darken 'foreground 10)))
(:discard (:anything t))))))))
("w" "Week agenda"
((agenda "" ((org-super-agenda-groups
`((:discard (:file-path "graveyard"))
(:discard (:todo "MAYBE"))
(:discard (:file-path "inbox"))
(:auto-planning t)
(:auto-planning t)))))
(alltodo ""
((org-agenda-overriding-header "")
(org-super-agenda-groups
`((:discard (:file-path "graveyard"))
(:discard (:file-path "maybe"))
(:discard (:todo "MAYBE"))
(:discard (:scheduled t))
(:discard (:deadline t))
(:name "Unscheduled"
:todo ("EVENT" "TODO")
:order 0)
(:discard (:anything t))))))))
("d" "Get back to work!"
((alltodo ""
((org-agenda-overriding-header "")
(org-super-agenda-groups
`((:discard (:file-path "graveyard"))
(:name "Maybe"
:todo "MAYBE"
:face (:foreground ,(technicolor-relative-darken 'foreground 70)
:height 0.9
:append t)
:order 100)
(:name "Important"
:priority "A"
:face (:foreground ,(technicolor-saturate 'red 20) :append t)
:order 1)
(:name "Ideas"
:todo "IDEA"
:face (:foreground ,(technicolor-get-color 'cyan)
:height 0.9
:append t)
:order 80)
(:name "Quick items"
:effort< "30"
:face (:foreground ,(technicolor-saturate 'blue 20) :append t))
(:auto-priority t)
(:order-multi (2 (:name "Research"
:tag "research"
:face (:foreground ,(technicolor-get-color 'cyan ) :append t))
(:name "Teaching"
:tag "teaching"
:face (:foreground ,(technicolor-get-color 'green ) :append t))))))))))
("l" "Todos"
((alltodo ""
((org-agenda-overriding-header "")
(org-super-agenda-groups
`((:discard (:file-path "graveyard"))
(:discard (:file-path "maybe"))
(:auto-planning t)
(:name "Ideas"
:todo "IDEA"
:face (:foreground ,(technicolor-get-color 'cyan)
:height 0.9
:append t)
:order 80)
(:name "Important"
:priority "A"
:face (:foreground ,(technicolor-saturate 'red 20) :append t)
:order 1)
(:order-multi (2 (:name "Research"
:tag "research"
:face (:foreground ,(technicolor-get-color 'cyan ) :append t))
(:name "Teaching"
:tag "teaching"
:face (:foreground ,(technicolor-get-color 'green ) :append t))))
(:name "Email"
:tag "email"
:order 20)
(:name "Personal"
:tag "personal"
:order 3)
(:auto-tags t
:order 50))))))))))
(after! org
(org-super-agenda-mode))
;;; ** `org' specific `expand-region' functionality
(after! org
(defun my/org-beginning-of-defun (&optional arg)
";TODO: "
(interactive "p")
(if (not (texmathp))
(org-backward-element)
(let ((lx (save-mark-and-excursion
(LaTeX-backward-environment arg)
(point)))
(beg (org-element-begin (org-element-context))))
(if (> beg lx) (goto-char beg)
(run-at-time 0 nil #'goto-char lx)
lx))))
(defun my/org-end-of-defun (&optional arg)
(interactive "p")
(if (not (texmathp))
(if (not (org-at-heading-p)))
(org-forward-element))
(org-forward-element)
(forward-char -1)
(goto-char (min (save-mark-and-excursion
(LaTeX-forward-environment (or arg 1))
(point))
(org-element-end (org-element-context))))))
;;; ** `org-mode-hook' main
(add-hook! org-mode
#'org-appear-mode
#'variable-pitch-mode
#'org-latex-preview-auto-mode
(org-indent-mode -1)
(require 'cdlatex)
(setq! display-line-numbers-mode nil
tab-width 8
smartparens-mode nil))
;;; ** `org' keybindings
(map! :map global-map
:desc "Org QL search" "C-c s q s" #'org-ql-search
:desc "Org QL find" "C-c s q f" #'org-ql-find
:desc "Org QL view" "C-c s q v" #'org-ql-view
(:when (modulep! :lang org +roam2)
:desc "org-roam-ql search" "C-c n r q" #'org-roam-ql-search)
(:when (modulep! :completion vertico)
:desc "Search org agenda" "C-c s a" #'consult-org-agenda))
(map! :map org-mode-map
:desc "Math delim insert" "M-m" #'math-delimiters-insert
:desc "Insert bibliography link" "C-c ]" #'org-cite-insert
:desc "Forward LaTeX math" "C-c L f" #'forward-latex-math
:desc "Backward LaTeX math" "C-c L b" #'backward-latex-math
:desc "Add note" "C-c z" #'org-add-note
:desc "Outline" "C-c s ," #'consult-org-heading
:desc "Make ink figure" "C-c i i" #'ink-make-figure
:desc "Make quiver (local)" "C-c i c l" #'open-quiver-local
:desc "Make quiver (online)" "C-c i c w" #'open-quiver-web
:desc "Forward LaTeX math" "M-TAB" #'forward-latex-math
:desc "Backward LaTeX math" "M-<iso-lefttab>" #'backward-latex-math)
;;; * `expand-region'
(after! expand-region
(setq! expand-region-fast-keys-enabled nil)
(defvar-keymap expand-region-repeat-map
:repeat ((:enter er/expand-region
er/contract-region))
"," #'er/expand-region
"." #'er/contract-region))
(advice-add 'er--first-invocation
:override
(defun my/er--first-invocation ()
"t if this is the first invocation of er/expand-region or er/contract-region"
(not (memq last-command
'(er/expand-region er/contract-region
easy-kill-expand-region easy-kill-contract-region)))))
(add-to-list 'expand-region-exclude-text-mode-expansions 'org-mode)
(add-to-list 'expand-region-exclude-text-mode-expansions 'latex-mode)
;;; ** Helper functions
;;; *** LaTeX stuff expansions
(after! expand-region
(defun er/mark-LaTeX-inside-math ()
"Mark text inside LaTeX math delimiters. See `er/mark-LaTeX-math'
for details."
(when (texmathp)
(let* ((string (car texmathp-why))
(pos (cdr texmathp-why))
(reason (assoc string texmathp-tex-commands1))
(type (cadr reason)))
(cond
;; I never use $ $$ for latex math. I mean, who does??
;; ((eq type 'sw-toggle) ;; $ and $$
;; (goto-char pos)
;; (set-mark (1+ (point)))
;; (forward-sexp 1)
;; (backward-char 1)
;; (exchange-point-and-mark))
((or (eq type 'sw-on)
(equal string "Org mode embedded math")) ;; \( and \[
(re-search-forward texmathp-onoff-regexp)
(backward-char 2)
(set-mark (+ pos 2))
(exchange-point-and-mark))
(t (error (format "Unknown reason to be in math mode: %s" type)))))))
(defun er/mark-latex-inside-pairs ()
(if (texmathp)
(cl-destructuring-bind (beg . end)
(my/find-bounds-of-regexps " *[{([|<]"
" *[]})|>]")
(when-let ((n (length (match-string-no-properties 0))))
(set-mark
(save-excursion
(goto-char beg)
(forward-char n)
(skip-chars-forward er--space-str)
(point)))
(goto-char end)
(backward-char n)
(if (looking-back "\\\\right\\\\*\\|\\\\" (- (point) 7))
(backward-char (length (match-string-no-properties 0))))
(skip-chars-backward er--space-str)
(exchange-point-and-mark)))
(er/mark-inside-pairs)))
(defun er/mark-latex-outside-pairs ()
(if (texmathp)
(cl-destructuring-bind (beg . end)
(my/find-bounds-of-regexps " *[{([|<]"
" *[]})|>]")
(set-mark (save-excursion
(goto-char beg)
;; (forward-char 1)
(if (looking-back "\\\\left\\\\*\\|\\\\" (- (point) 6))
(backward-char (length (match-string-no-properties 0))))
(skip-chars-forward er--space-str)
(point)))
(goto-char end)
(skip-chars-backward er--space-str)
;; (backward-char 1)
(exchange-point-and-mark))
(er/mark-outside-pairs))))
;;; **** `org-mode' and `expand-region' latex interop
(defun er/add-latex-in-org-mode-expansions ()
(require 'expand-region)
;; Make Emacs recognize \ as an escape character in org
(modify-syntax-entry ?\\ "\\" org-mode-syntax-table)
;; Paragraph end at end of math environment
(setq paragraph-start (concat paragraph-start "\\|\\\\end{\\([A-Za-z0-9*]+\\)}"))
;; (setq paragraph-separate (concat paragraph-separate "\\|\\\\end{\\([A-Za-z0-9*]+\\)}"))
;; Better forward/backward defun in Org
(setq-local beginning-of-defun-function 'my/org-beginning-of-defun)
;; Latex mode expansions
(set (make-local-variable 'er/try-expand-list)
(append (cl-set-difference er/try-expand-list
'(er/mark-method-call
er/mark-inside-pairs
er/mark-outside-pairs))
'(LaTeX-mark-environment
er/mark-LaTeX-inside-math
er/mark-latex-inside-pairs
er/mark-latex-outside-pairs
er/mark-LaTeX-math))))
(add-hook! org-mode #'er/add-latex-in-org-mode-expansions)
;;; * `tempel'
;;; ** Basic setup
(after! tempel
(defun tempel-setup-capf ()
;; Add the Tempel Capf to `completion-at-point-functions'.
;; `tempel-expand' only triggers on exact matches. Alternatively use
;; `tempel-complete' if you want to see all matches, but then you
;; should also configure `tempel-trigger-prefix', such that Tempel
;; does not trigger too often when you don't expect it. NOTE: We add
;; `tempel-expand' *before* the main programming mode Capf, such
;; that it will be tried first.
(setq-local completion-at-point-functions
(cons #'tempel-expand
completion-at-point-functions)))
(add-hook! prog-mode #'tempel-setup-capf)
(add-hook! text-mode #'tempel-setup-capf)
(setq! tempel-path (directory-files (concat doom-user-dir "templates") t "eld$")
tempel-auto-reload t))
;;; ** `tempel' keybindings
(map! :map tempel-map
"M-n" #'tempel-next
"M-e" #'tempel-previous
"C-M-k" #'tempel-abort)
;;; * `org-roam'
;; Will be removed eventually (maybe).
;; I think I prefer the zen of `org-node',
;; but some of the `org-roam' features are
;; really nice to have
;;; ** `Variables'
(after! org-roam
(setq! org-roam-directory "~/Documents/org/roam/"
org-roam-dailies-directory "~/Documents/org/roam/daily/"
org-roam-node-display-template
(concat "${title:*} "
(propertize "${tags:40}" 'face 'org-modern-tag))
org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag))
citar-org-roam-note-title-template "${author} - ${title}"
citar-org-roam-capture-template-key "b"))
(add-hook! org-roam-mode (visual-line-mode
(org-latex-preview 'buffer)))
(after! org
;; function to add a citar key to ROAM_REFS property
;; for org-roam nodes
(defun citar-org-roam-tag-headline ( &optional rest )
(interactive)
(org-node--add-to-property-keep-space "ROAM_REFS" (s-concat "@" (car (citar--key-at-point)))))
(setq! org-node-warn-title-collisions nil
org-node-creation-fn #'org-capture)
(org-node-cache-mode))
;;; ** `org-roam' helper functions
;; This code is just helper stuff that I wrote
;; to migrate my org-roam collection to a single big file
;; as opposed to many small files. Organizationally, I find
;; the latter preferable because the in-buffer search utilities
;; are superior, and I arbitrarily prefer fewer buffers
;; open at a time. You can safely delete this code.
(after! nil
(defun org-roam-file-to-heading (file buff)
"Moves content from single `org-roam' node FILE to a top
level heading in BUFF"
(org-with-file-buffer file
(let ((title (org-get-title))
(tags (mapcar #'substring-no-properties (org-roam-node-tags (org-roam-node-at-point))))
(props (cl-remove-if (lambda (x) (member (car x) '("ALLTAGS" "FILE")))
(org-roam-node-properties (org-roam-node-at-point))))
(content (progn (goto-char (point-min))
(org-roam-end-of-meta-data t)
(s-replace-regexp
org-heading-regexp
"*\\1 \\2"
(buffer-substring-no-properties (point) (buffer-end 1))))))
(message (format "Copying file: %s" file))
(switch-to-buffer buff)
(org-insert-heading nil t 1)
(cl-loop for tag in tags
initially (insert title " :")
finally (insert ":\n") do
(insert ":" tag))
(cl-loop for (prop . val) in props
finally (insert "\n" content) do
(org-set-property prop val)))))
(defun org-roam-files-to-headings (buff)
"Refactors all `org-roam' nodes in one-node-per-file
format to top level headlines in `org' buffer BUFF"
(interactive)
(cl-loop for file in (directory-files org-roam-directory t "\\.org$")
do
(my/org-roam-file-to-heading file buff))))
;;; ** Solving org-roam file ID annoyance
(quickroam-mode)
(after! org-roam
(defun my/remove-file-level-org-ID ()
"Removes file-level org ID property.
`org-roam' forces new ID creation at the file level
regardless of the type of capture template. I want to use
headlines as entries, hence the adding of this function
to the post-capture hook."
(save-excursion
(goto-char (point-min))
(org-delete-property "ID")))
(add-hook! org-roam-capture-new-node #'my/remove-file-level-org-ID))
;;; ** `org-roam' keybindings
(map! :map global-map
:leader
(:prefix-map ("n r" . "node")
:desc "Insert node" "i" #'org-node-insert-link
:desc "Find node" "f" #'org-node-find
:desc "Refile node" "w" #'org-node-refile)
;; (:prefix-map ("n d" . "dailies")
;; :desc "Capture today" "n" #'org-roam-dailies-capture-today
;; :desc "Capture y'day" "y" #'org-roam-dailies-capture-yesterday
;; :desc "Capture tomorrow" "t" #'org-roam-dailies-capture-tomorrow
;; :desc "Goto today" "f" #'org-roam-dailies-goto-today
;; :desc "Goto date" "d" #'org-roam-dailies-goto-date)
)
;;; * `citar'
;;; ** variables
(after! citar
(setq! citar-bibliography '("~/Documents/bib/zotero_refs.bib")
citar-org-roam-subdir "~/Documents/org/roam/"
bibtex-completion-library-path '("~/Documents/books/" "~/Documents/bib/pdfs/")
citar-org-roam-template-fields '((:citar-title "title")
(:citar-author "author" "editor")
(:citar-date "date" "year" "issued")
(:citar-pages "pages")
(:citar-type "=type=")
(:citar-citekey "citekey")
(:citar-file "file"))
citar-org-roam-capture-template-key "n"))
;;; ** `citar' related keybindings
(defun my/citar-embark-update-prefix-suffix (cite)
(citar-org-update-prefix-suffix nil))
(map! :map org-mode-map
:desc "Find node" "C-c n r f" #'org-node-find
:map citar-embark-map
:desc "Prefix/Suffix" "p" #'my/citar-embark-update-prefix-suffix
:desc "Open entry" "e" #'citar-open-entry
:desc "Open files" "f" #'citar-open-files
:desc "Edit" "i" #'citar-insert-edit
:desc "Open link" "l" #'citar-open-links
:desc "Open notes" "n" #'citar-open-notes
:desc "Open" "o" #'citar-open
:desc "Copy reference" "r" #'citar-copy-reference
:desc "Add to node refs" "k" #'citar-org-roam-tag-headline
:map citar-embark-citation-map
:desc "Prefix/Suffix" "p" #'my/citar-embark-update-prefix-suffix
:desc "Open entry" "e" #'citar-open-entry
:desc "Open files" "f" #'citar-open-files
:desc "Edit" "i" #'citar-insert-edit
:desc "Open link" "l" #'citar-open-links
:desc "Open notes" "n" #'citar-open-notes
:desc "Open" "o" #'citar-open
:desc "Copy reference" "r" #'citar-copy-reference
:desc "Add to node refs" "k" #'citar-org-roam-tag-headline)
;;; * `pdf-view' mode
(pdf-loader-install)
(after! pdf-tools
(add-hook! pdf-tools-enabled #'pdf-view-themed-minor-mode
#'pdf-view-auto-slice-minor-mode))
;;; ** `pdf' keybindings
(map! :map pdf-view-mode-map
"M-m" #'pdf-view-auto-slice-minor-mode
"M-f" #'pdf-view-themed-minor-mode
"n" #'pdf-view-next-line-or-next-page
"e" #'pdf-view-previous-line-or-previous-page)
;;; * `avy'
;;; ** `avy' functions
(use-package! avy-utils
:after avy
:load-path local-package-path)
;;; ** `avy' variables
(after! avy
(setq! avy-keys '(?a ?r ?s ?t ?n ?e ?i ?o)
avy-timeout-seconds 0.30
avy-all-windows t
avy-all-windows-alt nil
avy-dispatch-alist '((?m . avy-action-mark)
(?. . avy-action-embark)
(?x . avy-action-exchange)
(?, . avy-action-push-mark-no-activate)
(?l . avy-action-kill-line)
(?Y . avy-action-yank-line)
(?k . avy-action-kill-stay)
(?y . avy-action-yank)
(?f . avy-action-teleport)
(?L . avy-action-copy-whole-line)
(?K . avy-action-kill-whole-line)
(?Y . avy-action-yank-whole-line)
(?T . avy-action-teleport-whole-line))))
;;; * `corfu'
;;; ** `corfu' variables
(after! corfu
(setq! corfu-cycle t