-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.el
1555 lines (1298 loc) · 55.6 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
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;;;------ User configuration ------;;;
;; Import relevant system variables from flake (see doom.nix)
;; includes variables like user-full-name, user-username, user-home-directory, user-email-address, doom-font,
;; and a few other custom variables I use later
(load! "~/.emacs.d/system-vars.el")
;; custom variables include:
;; dotfiles-dir, absolute path to home directory
;; user-default-roam-dir, name of default org-roam directory for the machine (relative to ~/Org)
;; system-nix-profile, profile selected from my dotfiles ("personal" "work" "wsl" etc...)
;; system-wm-type, wayland or x11? only should be considered if system-nix-profile is "personal" or "work"
;; I prefer visual lines
(setq display-line-numbers-type 'visual
line-move-visual t)
(use-package-hook! evil
:pre-init
(setq evil-respect-visual-line-mode t) ;; sane j and k behavior
t)
;; I also like evil mode visual movement
(map! :map evil-normal-state-map
:desc "Move to next visual line"
"j" 'evil-next-visual-line
:desc "Move to previous visual line"
"k" 'evil-previous-visual-line)
;; Theme
(setq custom-theme-directory "~/.emacs.d/themes")
(setq doom-theme 'doom-stylix)
;; +unicode-init-fonts-h often errors out
(remove-hook 'doom-init-ui-hook '+unicode-init-fonts-h)
;; Transparent background
(if (string= system-nix-profile "wsl")
;; Can't be that tranparent under wsl because no blur
(funcall (lambda ()
(set-frame-parameter nil 'alpha-background 98)
(add-to-list 'default-frame-alist '(alpha-background . 98))
))
;; On Linux I can enable blur, however
(funcall (lambda ()
(set-frame-parameter nil 'alpha-background 85)
(add-to-list 'default-frame-alist '(alpha-background . 85))
))
)
(add-to-list 'default-frame-alist '(inhibit-double-buffering . t))
;; Icons in completion buffers
(add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup)
(all-the-icons-completion-mode)
;; Grammar tasing should be voluntary
(setq writegood-mode nil)
;; Beacon shows where the cursor is, even when fast scrolling
(setq beacon-mode t)
(setq company-idle-delay 0.05)
;; Quicker window management keybindings
(bind-key* "C-j" #'evil-window-down)
(bind-key* "C-k" #'evil-window-up)
(bind-key* "C-h" #'evil-window-left)
(bind-key* "C-l" #'evil-window-right)
(bind-key* "C-q" #'evil-window-delete)
(bind-key* "M-q" #'kill-current-buffer)
(bind-key* "M-w" #'+workspace/close-window-or-workspace)
(bind-key* "M-n" #'next-buffer)
(bind-key* "M-p" #'previous-buffer)
(bind-key* "M-z" #'+vterm/toggle)
(bind-key* "M-e" #'+eshell/toggle)
(bind-key* (kbd "M-<return>") #'+vterm/here)
(bind-key* (kbd "M-E") #'+eshell/here)
;; Buffer management
(bind-key* "<mouse-9>" #'next-buffer)
(bind-key* "<mouse-8>" #'previous-buffer)
;; Disables custom.el
(setq custom-file null-device)
;; emacs-dashboard setup
(require 'all-the-icons)
(require 'dashboard)
(setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*"))
doom-fallback-buffer-name "*dashboard*")
(setq image-scaling-factor 1)
;; emacs-dashboard variables
(setq dashboard-banner-logo-title "Welcome to Nix Doom Emacs")
(setq dashboard-startup-banner "~/.emacs.d/dashboard-logo.webp")
(setq dashboard-icon-type 'all-the-icons) ;; use `all-the-icons' package
(setq dashboard-set-heading-icons t)
(setq dashboard-set-file-icons t)
(setq dashboard-set-navigator t)
(setq dashboard-items '())
(setq dashboard-center-content t)
(setq dashboard-footer-messages '("Here to do customizing, or actual work?"
"M-x insert-inspiring-message"
"My software never has bugs. It just develops random features."
"Dad, what are clouds made of? Linux servers, mostly."
"There is no place like ~"
"~ sweet ~"
"sudo chown -R us ./allyourbase"
"I’ll tell you a DNS joke but it could take 24 hours for everyone to get it."
"I'd tell you a UDP joke, but you might not get it."
"I'll tell you a TCP joke. Do you want to hear it?"))
;; Remove basic evil input and cursors from dashboard
(defun disable-cursor()
(setq-local evil-normal-state-cursor '(bar . 0))
(hl-line-mode -1)
)
(add-hook 'dashboard-mode-hook 'disable-cursor)
(evil-define-key 'normal dashboard-mode-map
"j" 'evil-normal-state
"k" 'evil-normal-state
"h" 'evil-normal-state
"l" 'evil-normal-state)
(setq dashboard-navigator-buttons
`(;; line1
( (,"Roam" "" "" (lambda (&rest _)) 'org-formula)
(,(all-the-icons-octicon "globe" :height 1.0 :v-adjust 0.0)
"Notes overview" "" (lambda (&rest _) (org-roam-default-overview)) 'org-formula)
(,(all-the-icons-fileicon "org" :height 1.0 :v-adjust 0.0)
"Switch roam db" "" (lambda (&rest _) (org-roam-switch-db)) 'org-formula)
)
;; line 2
( (,"Git" "" "" (lambda (&rest _)) 'diredfl-exec-priv)
(,(all-the-icons-octicon "mark-github" :height 1.0 :v-adjust 0.0)
"GitHub" "" (lambda (&rest _) (browse-url "https://github.com/librephoenix")) 'diredfl-exec-priv)
(,(all-the-icons-faicon "gitlab" :height 1.0 :v-adjust 0.0)
"GitLab" "" (lambda (&rest _) (browse-url "https://gitlab.com/librephoenix")) 'diredfl-exec-priv)
(,(all-the-icons-faicon "coffee" :height 1.0 :v-adjust 0.0)
"Gitea" "" (lambda (&rest _) (browse-url my-gitea-domain)) 'diredfl-exec-priv)
(,(all-the-icons-octicon "triangle-up" :height 1.2 :v-adjust -0.1)
"Codeberg" "" (lambda (&rest _) (browse-url "https://codeberg.org/librephoenix")) 'diredfl-exec-priv)
)
;; line 3
( (,"Agenda" "" "" (lambda (&rest _)) 'dired-warning)
(,(all-the-icons-octicon "checklist" :height 1.0 :v-adjust 0.0)
"Agenda todos" "" (lambda (&rest _) (org-agenda-list)) 'dired-warning)
(,(all-the-icons-octicon "calendar" :height 1.0 :v-adjust 0.0)
"Agenda calendar" "" (lambda (&rest _) (cfw:open-org-calendar)) 'dired-warning)
)
;; line 4
( (,"Config" "" "" (lambda (&rest _)) 'dired-mark)
(,(all-the-icons-faicon "cogs" :height 1.0 :v-adjust 0.0)
"System config" "" (lambda (&rest _) (projectile-switch-project-by-name "~/.dotfiles" t)) 'dired-mark)
(,(all-the-icons-material "help" :height 1.0 :v-adjust -0.2)
"Doom documentation" "" (lambda (&rest _) (doom/help)) 'dired-mark)
)))
(setq dashboard-footer-icon
(all-the-icons-faicon "list-alt"
:height 1.0
:v-adjust -0.15
:face 'font-lock-keyword-face))
(dashboard-setup-startup-hook)
(map! :leader :desc "Open dashboard" "b b" #'dashboard-refresh-buffer)
;; Smooth scrolling
;; requires good-scroll.el
;;(good-scroll-mode 1)
;;(setq good-scroll-duration 0.4
;; good-scroll-step 270
;; good-scroll-render-rate 0.03)
;;
;;(global-set-key (kbd "<next>") #'good-scroll-up-full-screen)
;;(global-set-key (kbd "<prior>") #'good-scroll-down-full-screen)
(setq scroll-margin 30)
(setq hscroll-margin 10)
;; Requires for faster loading
(require 'org-agenda)
(require 'dired)
;; Garbage collection to speed things up
(add-hook 'after-init-hook
#'(lambda ()
(setq gc-cons-threshold (* 100 1024 1024))))
(add-hook 'focus-out-hook 'garbage-collect)
(run-with-idle-timer 5 t 'garbage-collect)
;; Enable autorevert globally so that buffers update when files change on disk.
;; Very useful when used with file syncing (i.e. syncthing)
(setq global-auto-revert-mode nil)
(setq auto-revert-use-notify t)
;; Neotree fun
(defun neotree-snipe-dir ()
(interactive)
(if (projectile-project-root)
(neotree-dir (projectile-project-root))
(neotree-dir (file-name-directory (file-truename (buffer-name))))
)
)
(map! :leader :desc "Open neotree here" "o n" #'neotree-snipe-dir
:desc "Hide neotree" "o N" #'neotree-hide)
;; For camelCase
(global-subword-mode 1)
;; ripgrep as grep
(setq grep-command "rg -nS --no-heading "
grep-use-null-device nil)
;; Mini-frames ;; cool but kinda suboptimal atm
;(add-load-path! "~/.emacs.d/mini-frame")
;(require 'mini-frame)
;(setq mini-frame-ignore-commands '(evil-ex-search-forward helpful-variable helpful-callable))
;(setq mini-frame-show-parameters
; '((left . 216)
; (top . 240)
; (width . 0.78)
; (height . 20)
; (alpha-background . 90))
;)
;(setq mini-frame-detach-on-hide nil)
;(setq mini-frame-resize t)
;(setq resize-mini-frames t)
;(setq mini-frame-standalone nil)
;(mini-frame-mode 1)
;;;------ Registers ------;;;
(map! :leader
:desc "Jump to register"
"r" 'jump-to-register)
(if (string= system-nix-profile "personal") (set-register ?f (cons 'file (concat user-home-directory "/Org/Family.s/Notes/hledger.org"))))
(set-register ?h (cons 'file user-home-directory))
(set-register ?r (cons 'file (concat dotfiles-dir "/README.org")))
;;;------ Org mode configuration ------;;;
;; Set default org directory
(setq org-directory "~/Org")
(setq org-attach-directory "~/Org/.attach")
(setq org-attach-id-dir "~/Org/.attach")
(setq org-id-locations-file "~/Org/.orgids")
(remove-hook 'after-save-hook #'+literate|recompile-maybe)
(set-company-backend! 'org-mode nil)
;; Automatically show images but manually control their size
(setq org-startup-with-inline-images t
org-image-actual-width nil)
(require 'evil-org)
(require 'evil-org-agenda)
(add-hook 'org-mode-hook 'evil-org-mode -100)
;; Top-level headings should be bigger!
(custom-set-faces!
`(outline-1 :height 1.3 :foreground ,(nth 1 (nth 14 doom-themes--colors)))
`(outline-2 :height 1.25 :foreground ,(nth 1 (nth 15 doom-themes--colors)))
`(outline-3 :height 1.2 :foreground ,(nth 1 (nth 19 doom-themes--colors)))
`(outline-4 :height 1.1 :foreground ,(nth 1 (nth 23 doom-themes--colors)))
`(outline-5 :height 1.1 :foreground ,(nth 1 (nth 24 doom-themes--colors)))
`(outline-6 :height 1.1 :foreground ,(nth 1 (nth 16 doom-themes--colors)))
`(outline-7 :height 1.05 :foreground ,(nth 1 (nth 18 doom-themes--colors)))
`(outline-8 :height 1.05 :foreground ,(nth 1 (nth 11 doom-themes--colors)))
'(variable-pitch :family "Intel One Mono")
`(org-agenda-date :inherit 'unspecified :foreground ,(nth 1 (nth 19 doom-themes--colors)) :weight bold :height 1.1)
`(org-agenda-date-today :inherit 'unspecified :foreground ,(nth 1 (nth 15 doom-themes--colors)) :weight bold :height 1.1)
`(org-agenda-date-weekend :inherit 'unspecified :foreground ,(nth 1 (nth 24 doom-themes--colors)) :weight bold :height 1.1)
`(org-agenda-date-weekend-today :inherit 'unspecified :foreground ,(nth 1 (nth 15 doom-themes--colors)) :weight bold :height 1.1)
)
(after! org (org-eldoc-load))
(with-eval-after-load 'org (global-org-modern-mode))
;; Add frame borders and window dividers
(modify-all-frames-parameters
'((right-divider-width . 5)
(internal-border-width . 5)))
(dolist (face '(window-divider
window-divider-first-pixel
window-divider-last-pixel))
(face-spec-reset-face face)
(set-face-foreground face (face-attribute 'default :background)))
(set-face-background 'fringe (face-attribute 'default :background))
(setq
;; Edit settings
org-auto-align-tags nil
org-tags-column 0
org-catch-invisible-edits 'show-and-error
org-special-ctrl-a/e t
org-insert-heading-respect-content t
;; Org styling, hide markup etc.
org-hide-emphasis-markers t
org-pretty-entities t
org-ellipsis "…")
(setq-default line-spacing 0)
; Automatic table of contents is nice
(if (require 'toc-org nil t)
(progn
(add-hook 'org-mode-hook 'toc-org-mode)
(add-hook 'markdown-mode-hook 'toc-org-mode))
(warn "toc-org not found"))
;;---- this block from http://fgiasson.com/blog/index.php/2016/06/21/optimal-emacs-settings-for-org-mode-for-literate-programming/ ----;;
;; Tangle Org files when we save them
(defun tangle-on-save-org-mode-file()
(when (string= (message "%s" major-mode) "org-mode")
(org-babel-tangle)))
(add-hook 'after-save-hook 'tangle-on-save-org-mode-file)
;; ---- end block ---- ;;
;; Better org table editing
;; This breaks multiline visual block edits
;;(setq-default evil-insert-state-exit-hook '(org-update-parent-todo-statistics
;; t))
;;(setq org-table-automatic-realign nil)
;; Better for org source blocks
(setq electric-indent-mode nil)
(setq org-src-window-setup 'current-window)
(set-popup-rule! "^\\*Org Src"
:side 'top'
:size 0.9)
;; Horizontal scrolling tables
(add-load-path! "~/.emacs.d/phscroll")
(setq org-startup-truncated nil)
(with-eval-after-load "org"
(require 'org-phscroll))
(setq phscroll-calculate-in-pixels t)
;; Org side tree outline
(add-load-path! "~/.emacs.d/org-side-tree")
(require 'org-side-tree)
(setq org-side-tree-persistent nil)
(setq org-side-tree-fontify t)
(setq org-side-tree-enable-folding t)
(defun org-side-tree-create-or-toggle ()
(interactive)
(if (or (org-side-tree-has-tree-p) (eq major-mode 'org-side-tree-mode))
(org-side-tree-toggle)
(org-side-tree)))
(map! :leader
"O t" #'org-side-tree-create-or-toggle)
(map! :map org-side-tree-mode-map
"SPC" nil)
(require 'org-download)
;; Drag-and-drop to `dired`
(add-hook 'dired-mode-hook 'org-download-enable)
;; system-wm-type, wayland or x11? only should be considered if system-nix-profile is "personal" or "work"
(if (string= system-wm-type "wayland")
(setq org-download-screenshot-method "grim -g \"$(slurp)\" %s")
(setq org-download-screenshot-method "flameshot gui -p %s")
)
(after! org-download
(setq org-download-method 'directory))
(after! org
(setq-default org-download-image-dir "img/"
org-download-heading-lvl nil))
(add-to-list 'display-buffer-alist '("^*Async Shell Command*" . (display-buffer-no-window)))
(defun org-download-clipboard-basename ()
(interactive)
(setq org-download-path-last-dir org-download-image-dir)
(setq org-download-image-dir (completing-read "directory: " (-filter #'f-directory-p (directory-files-recursively "." "" t)) nil t))
(org-download-clipboard (completing-read "basename: " '() nil nil))
(setq org-download-image-dir org-download-path-last-dir)
)
(map! :leader
:desc "Insert a screenshot"
"i s" 'org-download-screenshot
:desc "Insert image from clipboard"
"i p" 'org-download-clipboard
"i P" 'org-download-clipboard-basename)
(defun org-new-file-from-template()
"Copy a template from ~/Templates into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
(interactive)
(setq template-file (completing-read "Template file:" (directory-files "~/Templates")))
(setq filename
(concat
(make-temp-name
(concat (file-name-directory (buffer-file-name))
"files/"
(file-name-nondirectory (buffer-file-name))
"_"
(format-time-string "%Y%m%d_%H%M%S_")) ) (file-name-extension template-file t)))
(copy-file (concat user-home-directory "/Templates/" template-file) filename)
(setq prettyname (read-from-minibuffer "Pretty name:"))
(insert (concat "[[./files/" (file-name-nondirectory filename) "][" prettyname "]]"))
(org-display-inline-images))
(map! :leader
:desc "Create a new file from a template and insert a link at point"
"i t" 'my-org-new-file-from-template)
(if (not (string= system-nix-profile "wsl"))
(when (require 'openwith nil 'noerror)
(setq openwith-associations
(list
(list (openwith-make-extension-regexp
'("mpg" "mpeg" "mp3" "mp4"
"avi" "wmv" "wav" "mov" "flv"
"ogm" "ogg" "mkv"))
"mpv"
'(file))
(list (openwith-make-extension-regexp
'("doc" "xls" "ppt" "odt" "ods" "odg" "odp"))
"libreoffice"
'(file))
'("\\.lyx" "lyx" (file))
'("\\.chm" "kchmviewer" (file))
(list (openwith-make-extension-regexp
'("pdf" "ps" "ps.gz" "dvi"))
"atril"
'(file))
(list (openwith-make-extension-regexp
'("kdenlive"))
"kdenlive-accel"
'(file))
(list (openwith-make-extension-regexp
'("kra"))
"krita"
'(file))
(list (openwith-make-extension-regexp
'("blend" "blend1"))
"blender"
'(file))
(list (openwith-make-extension-regexp
'("helio"))
"helio"
'(file))
(list (openwith-make-extension-regexp
'("svg"))
"inkscape"
'(file))
(list (openwith-make-extension-regexp
'("flp"))
"flstudio"
'(file))
(list (openwith-make-extension-regexp
'("mid"))
"rosegarden"
'(file))
))
(openwith-mode 1)))
(add-load-path! "~/.emacs.d/org-krita")
(require 'org-krita)
(add-hook 'org-mode-hook 'org-krita-mode)
(setq org-krita-extract-filename "preview.png")
(setq org-krita-scale 1)
(add-load-path! "~/.emacs.d/org-xournalpp")
(require 'org-xournalpp)
(add-hook 'org-mode-hook 'org-xournalpp-mode)
(setq org-xournalpp-template-getter
'(closure
(t)
nil
(file-truename "~/Templates/template.xopp") ; use my own template
)
)
;; override width to static 250 for now
;; so I don't have massive images in org mode (scrolling not fun)
(defun org-xournalpp--create-image (link refresh)
"Extract svg/png from given LINK and return image.
Regenerate the cached inline image, if REFRESH is true.
If the path from LINK does not exist, nil is returned."
(let ((width 250)
(xopp-path (f-expand (org-element-property :path link))))
(when (f-exists? xopp-path)
(if width
(create-image (org-xournalpp--get-image xopp-path refresh)
org-xournalpp-image-type
nil
:width width)
(create-image (org-xournalpp--get-image xopp-path refresh)
org-xournalpp-image-type
nil)))))
(defun org-copy-link-to-clipboard-at-point ()
"Copy current link at point into clipboard (useful for images and links)"
;; Remember to press C-g to kill this foreground process if it hangs!
(interactive)
(if (eq major-mode #'org-mode)
(link-hint-copy-link-at-point)
)
(if (eq major-mode #'ranger-mode)
(ranger-copy-absolute-file-paths)
)
(if (eq major-mode #'image-mode)
(image-mode-copy-file-name-as-kill)
)
(shell-command "~/.emacs.d/scripts/copy-link-or-file/copy-link-or-file-to-clipboard.sh " nil nil)
)
(if (string= system-nix-profile "wsl")
(map! :leader
:desc "Copy link at point"
"y y" 'link-hint-copy-link-at-point)
(map! :leader
:desc "Copy link/file at point into system clipbord (C-g to escape if copying a file)"
"y y" 'org-copy-link-to-clipboard-at-point))
;; Online images inside of org mode is pretty cool
;; This snippit is from Tobias on Stack Exchange
;; https://emacs.stackexchange.com/questions/42281/org-mode-is-it-possible-to-display-online-images
(require 'org-yt)
(defun org-image-link (protocol link _description)
"Interpret LINK as base64-encoded image data."
(cl-assert (string-match "\\`img" protocol) nil
"Expected protocol type starting with img")
(let ((buf (url-retrieve-synchronously (concat (substring protocol 3) ":" link))))
(cl-assert buf nil
"Download of image \"%s\" failed." link)
(with-current-buffer buf
(goto-char (point-min))
(re-search-forward "\r?\n\r?\n")
(buffer-substring-no-properties (point) (point-max)))))
(org-link-set-parameters
"imghttp"
:image-data-fun #'org-image-link)
(org-link-set-parameters
"imghttps"
:image-data-fun #'org-image-link)
;; Mermaid diagrams
(setq ob-mermaid-cli-path "~/.nix-profile/bin/mmdc")
;; Print org mode
(defun org-simple-print-buffer ()
"Open an htmlized form of current buffer and open in a web browser to print"
(interactive)
(htmlize-buffer)
(browse-url-of-buffer (concat (buffer-name) ".html"))
(sleep-for 1)
(kill-buffer (concat (buffer-name) ".html")))
;; Doesn't work yet, bc htmlize-region takes arguments BEG and END
;(defun org-simple-print-region()
; "Open an htmlized form of current region and open in a web browser to print"
; (interactive)
; (htmlize-region )
; (browse-url-of-buffer (concat (buffer-name) ".html"))
; (sleep-for 1)
; (kill-buffer (concat (buffer-name) ".html")))
(map! :leader
:prefix ("P" . "Print")
:desc "Simple print buffer in web browser"
"p" 'org-simple-print-buffer)
(map! :leader
:prefix ("P" . "Print")
:desc "Simple print buffer in web browser"
"b" 'org-simple-print-buffer)
;(map! :leader
; :prefix ("P" . "Print")
; :desc "Simple print region in web browser"
; "r" 'org-simple-print-region)
;; Display macros inline in buffers
(add-to-list 'font-lock-extra-managed-props 'display)
(font-lock-add-keywords
'org-mode
'(("\\({{{[a-zA-Z#%)(_-+0-9]+}}}\\)" 0
`(face nil display
,(format "%s"
(let* ((input-str (match-string 0))
(el (with-temp-buffer
(insert input-str)
(goto-char (point-min))
(org-element-context)))
(text (org-macro-expand el org-macro-templates)))
(if text
text
input-str)))))))
;; Org transclusion
(require 'org-transclusion)
(after! org
(map! :map global-map "<f12>" #'org-transclusion-add :leader :prefix "n" :desc "Org Transclusion Mode" "t" #'org-transclusion-mode)
(map! :leader :prefix "n" "l" #'org-transclusion-live-sync-start)
(setq org-transclusion-exclude-elements '(property-drawer keyword))
(add-hook 'org-mode-hook #'org-transclusion-mode)
)
(defun org-jekyll-new-post ()
(interactive)
(setq new-blog-post-title (read-from-minibuffer "Post name: "))
(setq new-blog-post-date (format-time-string "%Y-%m-%d" (date-to-time (org-read-date))))
(setq new-blog-post-slug (downcase (replace-regexp-in-string "[^[:alpha:][:digit:]_-]" "" (string-replace " " "-" new-blog-post-title))))
(setq new-blog-post-file (concat (projectile-project-root) "org/_posts/" new-blog-post-date "-" new-blog-post-slug ".org"))
(let ((org-capture-templates
`(("p" "New Jekyll blog post" plain (file new-blog-post-file)
,(concat "#+title: " new-blog-post-title "\n#+options: toc:nil num:nil\n#+begin_export html\n---\nlayout: post\ntitle: " new-blog-post-title "\nexcerpt: %?\ntags: \npermalink: " new-blog-post-date "-" new-blog-post-slug "\n---\n#+end_export\n\n#+attr_html: :alt " new-blog-post-title " :align center\n[[../assets/" new-blog-post-date "-" new-blog-post-slug ".png]]")))
)) (org-capture))
)
(defun org-jekyll-rename-post ()
(interactive)
(setq new-blog-post-title (read-from-minibuffer "Post name: "))
(setq new-blog-post-date (format-time-string "%Y-%m-%d" (date-to-time (org-read-date))))
(setq new-blog-post-slug (downcase (replace-regexp-in-string "[^[:alpha:][:digit:]_-]" "" (string-replace " " "-" new-blog-post-title))))
(org-roam-set-keyword "title" new-blog-post-title)
(replace-regexp "permalink: .*\n" (concat "permalink: " new-blog-post-date "-" new-blog-post-slug "\n") nil (point-min) (point-max))
(replace-regexp "title: .*\n" (concat "title: " new-blog-post-title "\n") nil (point-min) (point-max))
(setq prev-blog-post-filename-base (file-name-base (buffer-file-name)))
(doom/move-this-file (concat new-blog-post-date "-" new-blog-post-slug ".org"))
(shell-command (concat "sed -i s/" prev-blog-post-filename-base "/" (file-name-base (buffer-file-name)) "/g *.org") nil)
(replace-regexp prev-blog-post-filename-base (file-name-base (buffer-file-name)) nil (point-min) (point-max))
(save-buffer)
)
(map! :leader
:prefix ("N")
:desc "New blog post"
"p" #'org-jekyll-new-post
:desc "Rename or redate blog post and update links accordingly"
"e" #'org-jekyll-rename-post
)
(require 'crdt)
(setq crdt-default-tls nil)
(setq crdt-default-name "Emmet")
(if (file-exists-p "~/.emacs.d/crdt-private.el") (load! "~/.emacs.d/crdt-private.el"))
(defun crdt-connect-default ()
(interactive)
(crdt-connect crdt-default-server-address crdt-default-name)
)
(map! :leader
:desc "crdt"
:prefix ("C")
:desc "Connect to a crdt server"
"c" #'crdt-connect-default
:desc "Connect to default crdt server"
"C" #'crdt-connect-default
:desc "Disconnect from a crdt server"
"d" #'crdt-disconnect
:desc "Add buffer to a session"
"a" #'crdt-share-buffer
:desc "Stop sharing buffer to session"
"s" #'crdt-stop-share-buffer
:desc "List crdt buffers in a session"
"l" #'crdt-list-buffers
:desc "List crdt users in a session"
"u" #'crdt-list-users
)
;;;------ Org roam configuration ------;;;
(require 'org-roam)
(require 'org-roam-dailies)
(setq org-roam-directory (concat "~/Org/" user-default-roam-dir "/Notes")
org-roam-db-location (concat "~/Org/" user-default-roam-dir "/Notes/org-roam.db"))
(setq org-roam-node-display-template
"${title:65}📝${tags:*}")
(org-roam-db-autosync-mode)
(setq mode-line-misc-info '((which-function-mode
(which-func-mode
("" which-func-format " ")))
("" so-long-mode-line-info)
(global-mode-string
("" global-mode-string))
" "
org-roam-db-choice)
)
(setq org-roam-list-files-commands '(rg))
(setq full-org-roam-db-list nil)
(setq full-org-roam-db-list (directory-files "~/Org" t "\\.[p,s]$"))
(dolist (item full-org-roam-db-list)
(setq full-org-roam-db-list
(append (directory-files item t "\\.[p,s]$") full-org-roam-db-list)))
(setq org-roam-db-choice user-default-roam-dir)
(setq full-org-roam-db-list-pretty (list))
(dolist (item full-org-roam-db-list)
(setq full-org-roam-db-list-pretty
(append (list
(replace-regexp-in-string (concat "\\/home\\/" user-username "\\/Org\\/") "" item)) full-org-roam-db-list-pretty)))
(defun org-roam-open-dashboard ()
"Open ${org-roam-directory}/dashboard.org (I use this naming convention to create dashboards for each of my org roam maps)"
(interactive)
(if (file-exists-p (concat org-roam-directory "/dashboard.org"))
(org-open-file (concat org-roam-directory "/dashboard.org"))
(dired org-roam-directory))
)
(defun org-roam-open-inbox ()
"Capture info in ${org-roam-directory}/inbox.org (I use this naming convention to create dashboards for each of my org roam maps)"
(interactive)
(if (file-exists-p (concat org-roam-directory "/inbox.org"))
(org-open-file (concat org-roam-directory "/inbox.org"))
(message "No inbox found, capture something with M-x org-roam-capture-inbox"))
)
(defun org-roam-capture-inbox ()
(interactive)
(org-roam-capture- :node (org-roam-node-create)
:templates '(("i" "inbox" plain "* %?"
:if-new (file+head "inbox.org" "#+title: Inbox\n")))))
(defun org-roam-switch-db (&optional arg silent)
"Switch to a different org-roam database, arg"
(interactive)
(when (not arg)
(setq full-org-roam-db-list nil)
(setq full-org-roam-db-list (directory-files "~/Org" t "\\.[p,s]$"))
(dolist (item full-org-roam-db-list)
(setq full-org-roam-db-list
(append (directory-files item t "\\.[p,s]$") full-org-roam-db-list)))
(setq full-org-roam-db-list-pretty (list))
(dolist (item full-org-roam-db-list)
(setq full-org-roam-db-list-pretty
(append (list
(replace-regexp-in-string (concat "\\/home\\/" user-username "\\/Org\\/") "" item)) full-org-roam-db-list-pretty)))
(setq org-roam-db-choice (completing-read "Select org roam database: "
full-org-roam-db-list-pretty nil t)))
(when arg
(setq org-roam-db-choice arg))
(setq org-roam-directory (file-truename (concat "~/Org/" org-roam-db-choice "/Notes"))
org-roam-db-location (file-truename (concat "~/Org/" org-roam-db-choice "/Notes/org-roam.db"))
org-directory (file-truename (concat "~/Org/" org-roam-db-choice "/Notes")))
(when (not silent)
(org-roam-open-dashboard))
(org-roam-db-sync)
(message (concat "Switched to " org-roam-db-choice " org-roam database!")))
(defun org-roam-default-overview ()
(interactive)
(org-roam-switch-db user-default-roam-dir))
(defun org-roam-switch-db-id-open (arg ID &optional switchpersist)
"Switch to another org-roam db and visit file with id arg"
"If switchpersist is non-nil, stay in the new org-roam db after visiting file"
(interactive)
(setq prev-org-roam-db-choice org-roam-db-choice)
(org-roam-switch-db arg 1)
(org-roam-id-open ID)
(when (not switchpersist)
(org-roam-switch-db prev-org-roam-db-choice 1)))
;;;------ Org-roam-agenda configuration ------;;;
(defun text-in-buffer-p (TEXT)
(save-excursion (goto-char (point-min)) (search-forward TEXT nil t)))
(defun apply-old-todos-tag-maybe (&optional FILE)
(interactive)
(if (stringp FILE)
(setq the-daily-node-filename FILE)
(setq the-daily-node-filename buffer-file-name))
(if (org-roam-dailies--daily-note-p the-daily-node-filename)
(if (<= (nth 2 (org-roam-dailies-calendar--file-to-date the-daily-node-filename)) (nth 2 org-agenda-current-date))
(if (<= (nth 1 (org-roam-dailies-calendar--file-to-date the-daily-node-filename)) (nth 1 org-agenda-current-date))
(if (<= (nth 0 (org-roam-dailies-calendar--file-to-date the-daily-node-filename)) (nth 0 org-agenda-current-date))
(funcall (lambda ()
(with-current-buffer (get-file-buffer the-daily-node-filename) (org-roam-tag-add '("old-todos")))
(with-current-buffer (get-file-buffer the-daily-node-filename) (org-roam-tag-remove '("todos")))
)
)
)
)
)
)
)
(defun apply-old-todos-tag-maybe-and-save (FILE)
(interactive)
(find-file-noselect FILE)
(apply-old-todos-tag-maybe FILE)
(with-current-buffer (get-file-buffer the-daily-node-filename) (save-buffer))
(with-current-buffer (get-file-buffer the-daily-node-filename) (kill-buffer))
)
(defun org-current-buffer-has-todos ()
"Return non-nil if current buffer has any todo entry."
(org-element-map ; (2)
(org-element-parse-buffer 'headline) ; (1)
'headline
(lambda (h)
(eq (org-element-property :todo-type h)
'todo))
nil 'first-match)) ; (3)
(defun org-has-recent-timestamps (OLD-DAYS)
"Return non-nil only if current buffer has entries with timestamps
more recent than OLD-DAYS days"
(interactive)
(if (org-element-map (org-element-parse-buffer) 'timestamp
(lambda (h)
(org-element-property :raw-value h)))
(org-element-map ; (2)
(org-element-parse-buffer) ; (1)
'timestamp
(lambda (h)
(time-less-p (time-subtract (current-time) (* 60 60 24 OLD-DAYS)) (date-to-time (org-element-property :raw-value h))))
nil 'first-match) nil))
(setq org-timestamps-days-for-old 21)
; This has a bug where it won't sync a new agenda file
; if I'm editing an org roam node file while set to another
; org roam db
(defun add-todos-tag-on-save-org-mode-file()
(interactive)
(when (string= (message "%s" major-mode) "org-mode")
(if (org-roam-node-p (org-roam-node-at-point))
(funcall (lambda()
(if (or (org-current-buffer-has-todos) (org-has-recent-timestamps org-timestamps-days-for-old))
(org-roam-tag-add '("todos"))
(org-roam-tag-remove '("todos"))
)
(apply-old-todos-tag-maybe)
)
)
)
)
)
(add-hook 'before-save-hook 'add-todos-tag-on-save-org-mode-file)
(defun org-roam-filter-by-tag (tag-name)
(lambda (node)
(member tag-name (org-roam-node-tags node))))
(defun org-roam-list-notes-by-tag (tag-name)
(mapcar #'org-roam-node-file
(seq-filter
(org-roam-filter-by-tag tag-name)
(org-roam-node-list))))
(defun org-roam-dailies-apply-old-todos-tags-to-all ()
; (dolist (daily-node org-roam-dailies-files)
; (apply-old-todos-tag-maybe-and-save daily-node)
; )
(setq num 0)
(while (< num (list-length (org-roam-list-notes-by-tag "todos")))
(apply-old-todos-tag-maybe-and-save (nth num (org-roam-list-notes-by-tag "todos")))
(setq num (1+ num))
)
)
;; Refreshing org roam agenda
(defun org-roam-refresh-agenda-list ()
(interactive)
(setq prev-org-roam-db-choice org-roam-db-choice)
(setq org-agenda-files '())
(setq org-id-files '())
(setq org-roam-directory (file-truename "~/Org")
org-roam-db-location (file-truename "~/Org/org-roam.db")
org-directory (file-truename "~/Org/"))
(org-roam-db-sync)
(setq org-agenda-files (org-roam-list-notes-by-tag "todos"))
(setq org-id-files (org-roam-list-files))
(setq org-agenda-files (-uniq org-agenda-files))
(org-roam-switch-db prev-org-roam-db-choice 1)
)
;; Build agenda only when org agenda first opened for session
(setq org-roam-agenda-initialized nil)
(defun org-roam-refresh-agenda-list-init ()
(if (not org-roam-agenda-initialized)
(funcall
(lambda ()
(org-roam-refresh-agenda-list)
(setq org-roam-agenda-initialized t)
)
)
)
)
(add-hook 'org-agenda-mode-hook 'org-roam-refresh-agenda-list-init)
(map! :leader
:prefix ("o a")
:desc "Refresh org agenda from roam dbs"
"r" 'org-roam-refresh-agenda-list)
(map! :leader
:prefix ("N" . "org-roam notes")
:desc "Capture new roam node"
"c" 'org-roam-capture
:desc "Open org roam inbox"
"I o" 'org-roam-open-inbox
:desc "Capture stuff in inbox"
"I c" 'org-roam-capture-inbox
:desc "Insert roam node link at point"
"i" 'org-roam-node-insert
:desc "Find roam node"
"." 'org-roam-node-find
:desc "Switch org-roam database"
"s" 'org-roam-switch-db
:desc "Update current org-roam database"
"u" 'org-roam-db-sync
:desc "Re-zoom on current node in org-roam-ui"
"z" 'org-roam-ui-node-zoom
:desc "Visualize org-roam database with org-roam-ui"
"O" 'org-roam-default-overview
:desc "Visualize org-roam database with org-roam-ui"
"o" 'org-roam-open-dashboard)
(after! org-roam
(setq org-roam-capture-templates
'(("d" "default" plain "%?" :target
(file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
:unnarrowed t))))
(setq olivetti-style 'fancy
olivetti-margin-width 100)
(setq-default olivetti-body-width 100)
(defun org-roam-olivetti-mode ()
(interactive)
(if (org-roam-file-p)
(olivetti-mode))
(if (org-roam-file-p)
(doom-disable-line-numbers-h)))
(add-hook 'org-mode-hook 'org-roam-olivetti-mode)
(add-load-path! "~/.emacs.d/org-nursery/lisp")
(require 'org-roam-dblocks)
(add-hook 'org-mode-hook 'org-roam-dblocks-autoupdate-mode)
(setq org-id-extra-files 'org-agenda-text-search-extra-files)
;(add-to-list 'display-buffer-alist '("^\\ORUI" display-buffer-in-side-window
; '(side . right)
; (window-width . 50)
;))
;(add-to-list 'display-buffer-alist '("^\\localhost:35901" display-buffer-in-side-window
; '(side . right)
; (window-width . 50)
;))
;;(setq org-roam-ui-browser-function 'eaf-open-browser) ; xorg
(setq org-roam-ui-browser-function 'browse-url) ; wayland