-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
1762 lines (1538 loc) · 59.5 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
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; -*-
(setq package-enable-at-startup nil)
(setq use-package-ensure-function 'ignore)
(setq inhibit-startup-screen t)
(setq inhibit-startup-message t)
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(xterm-mouse-mode 1)
;;; Fonts
;; 5/30/22: https://www.reddit.com/r/emacs/comments/pc189c/fonts_in_emacs_daemon_mode/
;; 6/1/22: This setup correctly sets fonts on system boot
(defun jf/setup-font-faces ()
"Setup all customacs font faces."
;; ;;re-disable GUI stuff we don't care about
;; (push '(menu-bar-lines . 0) default-frame-alist)
;; (push '(tool-bar-lines . 0) default-frame-alist)
;; (push '(vertical-scroll-bars) default-frame-alist)
(defvar jf/default-font-size 100)
(defvar jf/default-variable-font-size 100)
(when (display-graphic-p)
(set-face-attribute 'default nil :font "Iosevka Custom" :height jf/default-font-size)
(set-face-attribute 'fixed-pitch nil :font "Iosevka Custom" :height jf/default-font-size)
(set-face-attribute 'variable-pitch nil :font "Iosevka Etoile" :height jf/default-variable-font-size)
))
;; run this hook after we have initialized the first time
(add-hook 'after-init-hook 'jf/setup-font-faces)
;; re-run this hook if we create a new frame from daemonized Emacs
(add-hook 'server-after-make-frame-hook 'jf/setup-font-faces)
;; org-mode
(setq org-use-extra-keys t)
;;; Inits
;; Code:
;; Heaviliy inspired by https://github.com/daviwil/emacs-from-scratch/blob/master/Emacs.org
;;;; Speedup Blub
;; https://www.reddit.com/r/emacs/comments/qw52na/emacs_271_earlyinit_file/hl0oo31/
(setq default-gc-threshold gc-cons-threshold
default-gc-percentage gc-cons-percentage)
(setq gc-cons-threshold most-positive-fixnum
default-gc-percentage 0.8)
(setq load-prefer-newer t)
(defun jf/display-startup-time ()
(message "Emacs loaded in %s with %d garbage collections."
(format "%.4f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done))
(add-hook 'emacs-startup-hook #'jf/display-startup-time)
;;;; Packages + Repos
;; Initialize package sources
(setq use-package-always-ensure t)
;;;;; auto-package-update
;; (use-package auto-package-update
;; :config
;; (setq auto-package-update-delete-old-versions t)
;; (setq auto-package-update-hide-results t)
;; (setq auto-package-update-prompt-before-update t)
;; (setq auto-package-update-show-preview t)
;; (auto-package-update-maybe)
;; (auto-package-update-at-time "14:00"))
;;;; Set up path
(use-package exec-path-from-shell
:init ;; (when (memq window-system '(mac ns x pgtk))
;; (exec-path-from-shell-initialize))
(when (daemonp)
(exec-path-from-shell-initialize)
(setenv "DISPLAY" ":0.0") ; used with emacsclients to open pdfs in zathura
))
;;;; auto-save
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups"))))
;;;; yes-or-no QoL
(defalias 'yes-or-no-p 'y-or-n-p)
;;;; emacsclient QoL
(defun save-buffers-kill-terminal--safe ()
"Based off 'save-buffers-kill-emacs'.
Wrapper around 'save-buffers-kill-terminal.
Meant to be used with emacsclient'"
(interactive)
(let ((confirm confirm-kill-emacs))
(and (or (null confirm)
(funcall confirm "Exit this emacsclient?"))
(save-buffers-kill-terminal))))
(use-package files
:ensure nil
:init (setq confirm-kill-emacs 'y-or-n-p)
:bind (("C-x C-c" . #'save-buffers-kill-terminal--safe)))
;;; Misc
(blink-cursor-mode -1)
(setq scroll-conservatively 101)
(delete-selection-mode 1)
(electric-pair-mode 1)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(use-package emacs
:ensure nil
:config
(setq initial-major-mode 'org-mode)
(setq initial-scratch-message ";; This buffer is for text that is not saved, and for org-mode usage.
#+begin_src elisp
(+ 1 1)
#+end_src
"))
;;; Usability
;;;; Vertico
(defun jf/vertico--backward-updir ()
"Delete char before or go up directory for file cagetory completions.
https://github.com/minad/vertico/issues/65#issuecomment-875094896"
(interactive)
(let ((metadata (completion-metadata (minibuffer-contents)
minibuffer-completion-table
minibuffer-completion-predicate)))
(if (and (eq (char-before) ?/)
(eq (completion-metadata-get metadata 'category) 'file))
(let ((new-path (minibuffer-contents)))
(delete-region (minibuffer-prompt-end) (point-max))
(insert (abbreviate-file-name
(file-name-directory
(directory-file-name
(expand-file-name new-path))))))
(call-interactively 'backward-delete-char))))
;; Make ESC quit prompts
;; (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
(use-package vertico
:bind (:map vertico-map
("DEL" . jf/vertico--backward-updir))
:init
(setq enable-recursive-minibuffers t)
(vertico-mode))
;;;; Savehist
(use-package savehist
:ensure nil
:init
(savehist-mode))
;;;; Marginalia
(use-package marginalia
:init
(marginalia-mode))
;;;; Orderless
;; https://github.com/minad/vertico#configuration
(use-package orderless
:init
(setq completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides '((file (styles partial-completion))))
(setq orderless-matching-styles '(orderless-regexp))
(setq read-file-name-completion-ignore-case t))
;;;; Embark
(use-package embark
:bind (("C-." . embark-act)
("C-;" . embark-dwim)
("C-h B" . embark-bindings))
:init (setq prefix-help-command #'embark-prefix-help-command)
:config (add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
(use-package embark-consult
:after (embark consult))
;;;; Consult
(use-package consult
:bind (;; C-c bindings (mode-specific-map)
("C-c h" . consult-history)
("C-c m" . consult-mode-command)
("C-c b b" . consult-bookmark)
("C-c k" . consult-kmacro)
;; C-x bindings (ctl-x-map)
("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
("C-x b" . consult-buffer) ;; orig. switch-to-buffer
("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
;; Custom M-# bindings for fast register access
("M-/" . consult-register-load)
("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
("M-\"" . consult-register)
;; Other custom bindings
("M-y" . consult-yank-pop) ;; orig. yank-pop
;; M-g bindings (goto-map)
("M-g e" . consult-compile-error)
("M-g g" . consult-goto-line) ;; orig. goto-line
("M-g M-g" . consult-goto-line) ;; orig. goto-line
("M-g o" . consult-outline) ;; Alternative: consult-org-heading
("M-g m" . consult-mark)
("M-g k" . consult-global-mark)
("M-g i" . consult-imenu)
("M-g I" . consult-imenu-multi)
;; M-s bindings (search-map)
("M-s f" . consult-find)
("M-s F" . consult-locate)
("M-s g" . consult-grep)
("M-s G" . consult-git-grep)
("M-s r" . consult-ripgrep)
("M-s l" . consult-line)
("M-s t" . (lambda () (interactive) (consult-line (hl-todo--regexp))))
("M-s L" . consult-line-multi)
("M-s m" . consult-multi-occur)
("M-s k" . consult-keep-lines)
("M-s u" . consult-focus-lines)
("M-g f" . consult-flymake))
:init
;; Use Consult to select xref locations with preview
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
:config
;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(setq consult-narrow-key "<") ;; (kbd "C-+")
;; Configure project.el (project-roots)
;; To return the project root directory.
(setq consult-project-root-function
(lambda ()
(when-let (project (project-current))
(car (project-roots project))))))
;;;; coalton-xref-stack
(use-package consult-xref-stack
:bind (("C-," . consult-xref-stack-backward)))
;;;; Which-key
(use-package which-key
:init
(which-key-mode))
;;;; Completion: Corfu
(use-package corfu
;; All from README
:custom
(corfu-separator ?\s) ;; Orderless field separator
(corfu-scroll-margin 1) ;; Use scroll margin
:init
(global-corfu-mode)
(completion-preview-mode 1)
(defun corfu-enable-always-in-minibuffer ()
"Enable Corfu in the minibuffer if Vertico/Mct are not active."
(unless (or (bound-and-true-p mct--active)
(bound-and-true-p vertico--input))
;; (setq-local corfu-auto nil) Enable/disable auto completion
(corfu-mode 1)))
(add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1))
;;; Window Management
;;;; Ace-window
(use-package ace-window
:bind* (("M-o" . 'ace-window))
:init (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
(setq aw-background nil)
(setq aw-display-mode-overlay nil)
(setq aw-scope 'frame)
(defun jf/ace-window-display--helper (left-delim right-delim)
(let ((pred (and ace-window-display-mode (< 2 (count-windows)))))
(when pred
(concat left-delim (window-parameter (get-buffer-window) 'ace-window-path) right-delim ))))
;; (add-hook 'ace-window-display-mode-hook #'jf/ace-window-message--helper)
)
(defun jf/window-split-toggle ()
"Toggle between horizontal and vertical split with two windows.
https://emacs.stackexchange.com/a/5372"
(interactive)
;; 11/10/22
;; trying to preserve ratio of either height or width
;; split-window-vert/horiz can take a char count
;; use window-full-height-p to determine current split
;; (let* ((ww (window-width))
;; (fw (frame-width))
;; (wh (window-height))
;; (fh (- (frame-height) 1))
;; (ratio (cond ((= ww fw) (/ wh (float fh)))
;; ((= wh fh) (/ ww (float fw)))
;; (t (error "Window size issue."))))))
(cond ((> (length (window-list)) 2)
(error "Can't toggle with more than 2 windows!"))
((= (length (window-list)) 1)
(error "Can't toggle only 1 window!"))
(t
(let ((func (if (window-full-height-p)
#'split-window-vertically
#'split-window-horizontally)))
(delete-other-windows)
(funcall func)
(save-selected-window
(other-window 1)
(switch-to-buffer (other-buffer)))))))
;;; Visual Interface
(use-package simple
:ensure nil
:init (setq-default fill-column 100)
(global-visual-line-mode)
:bind ("C-c j" . join-line))
;;;; Nano-modeline
(use-package nano-modeline
:after (ace-window)
:functions jf/ace-window-display--helper
:init (setq nano-modeline-position 'nano-modeline-header)
(ace-window-display-mode 1)
:config
;; Color logic implemented in modus-themes section
(defface nano-modeline-status-** '((t (:inherit nano-modeline-status))) "")
(add-to-list 'nano-modeline-faces '(status-**-active . (nano-modeline-status-**)))
(add-to-list 'nano-modeline-faces '(status-**-inactive . (nano-modeline-status-**)))
(defface nano-modeline-status-RW `((t (:inherit nano-modeline-status))) "")
(add-to-list 'nano-modeline-faces '(status-RW-active . (nano-modeline-status-RW)))
(add-to-list 'nano-modeline-faces '(status-RW-inactive . (nano-modeline-status-RW)))
(defun jf/nano-modeline-ace-display (left-delim right-delim)
"Extract window selecter chracter and wrap in LEFT-DELIM and RIGHT-DELIM.
Discovered window-parameter from https://oremacs.com/2015/03/12/ace-window-display-mode/."
(let ((pred (and ace-window-display-mode (< 2 (count-windows)))))
(when pred
(propertize
(concat left-delim
(substring-no-properties (window-parameter (selected-window) 'ace-window-path))
right-delim)
'face (nano-modeline-face 'name)))))
(defun jf/nano-modeline-my-mode (&optional default)
(funcall nano-modeline-position
'((nano-modeline-buffer-status) " "
(nano-modeline-buffer-name) " "
(nano-modeline-git-info "") " "
(jf/nano-modeline-ace-display "{" "}"))
'((nano-modeline-date nil "%a %y%m%d -") " "
(nano-modeline-cursor-position)
(nano-modeline-window-dedicated))
default))
(jf/nano-modeline-my-mode t)
(setq-default mode-line-format nil))
;;;; Modus-themes
(use-package modus-themes
:config
;; Add all your customizations prior to loading the themes
(setq modus-themes-italic-constructs t
modus-themes-bold-constructs nil
modus-themes-syntax '()
modus-themes-prompts '()
modus-themes-region '(bg-only no-extend)
modus-themes-mode-line '()
modus-themes-subtle-line-numbers t
modus-themes-org-blocks 'tinted-background
modus-themes-headings '((1 . (rainbow overline background))
(t . (rainbow overline no-bold)))
modus-themes-completions '((matches . (intense))
(selection . (accented intense))
(popup . (accented))))
(defun jf/modus-themes-custom-faces ()
;; [ status | name (primary) secondary ]
;; 230101: I believe these inherit from mode-line-active
(modus-themes-with-colors
(custom-set-faces
`(nano-modeline-active ((,c)))
`(nano-modeline-status-** ((,c :background ,bg-red-intense)))
`(nano-modeline-status-RW ((,c :background ,bg-blue-intense)))
`(magit-diff-context-highlight ((,c :background ,bg-cyan-nuanced)))
`(window-divider ((,c :background ,bg-main :foreground ,border)))
`(fringe ((,c :background ,fringe :foreground ,fg-main)))
`(denote-faces-year ((,c :foreground ,accent-0)))
`(denote-faces-month ((,c :foreground ,accent-1)))
`(denote-faces-day ((,c :foreground ,accent-2)))
`(denote-faces-hour ((,c :foreground ,fg-dim)))
`(denote-faces-minute ((,c :foreground ,fg-dim)))
`(denote-faces-second ((,c :foreground ,fg-dim))))
`(setq hl-todo-keyword-faces
'(("TODO" . ,red-intense)
("HOLD" . ,bg-yellow-intense)
("DONE" . ,green-intense)
("HACK" . ,blue-intense)
("NEXT" . ,magenta-cooler)
("NOTE" . ,cyan-intense)))
`(setq org-todo-keyword-faces
'(("TODO" . (:foreground ,red-intense :weight bold))
("HOLD" . (:foreground ,bg-yellow-intense :weight bold))
("DONE" . (:foreground ,green-intense :weight bold))
("NEXT" . (:foreground ,magenta-cooler :weight bold)))))
(hl-todo-mode -1)
(hl-todo-mode 1))
;; https://protesilaos.com/modus-themes/#h:1487c631-f4fe-490d-8d58-d72ffa3bd474
(add-hook 'modus-themes-after-load-theme-hook #'jf/modus-themes-custom-faces)
(modus-themes-load-theme 'modus-operandi)
:bind
("<f5>" . #'modus-themes-toggle))
;;;; window-divider
(use-package frame
:ensure nil
:init (setq window-divider-default-places 'bottom-only)
(setq window-divider-default-bottom-width 1)
(window-divider-mode))
;;; Fonts
;; fonts are set in early-init
;;; Hydra
(use-package hydra
:init
;; (defhydra hydra-text-scale (:timeout 4)
;; "scale text"
;; ("j" text-scale-increase "in")
;; ("k" text-scale-decrease "out")
;; ("f" nil "finished" :exit t))
)
;;; Org-mode
(use-package engrave-faces)
(defun mk/ignore-builtin (pkg)
(assq-delete-all pkg package--builtins)
(assq-delete-all pkg package--builtin-versions))
(mk/ignore-builtin 'org)
(use-package org
;; https://github.com/jwiegley/use-package/issues/955
;; does not work for built-ins
;; :pin gnu
;; Putting accessory org packages (in /custom/) before the main org package
;; will autoload the older version required by org-roam Setting the load-path
;; forces the new one to load
:load-path "elpa/org-9.6"
:init
;; (add-hook 'org-mode-hook #'rainbow-delimiters-mode)
(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)
:config ;; (setq org-ellipsis "")
(setq org-ellipsis " »")
(setq org-edit-src-content-indentation 0)
(setq org-preview-latex-default-process 'dvisvgm) ;https://stackoverflow.com/a/43943452
(setq org-latex-packages-alist '(("" "amsmath" t)))
(plist-put org-format-latex-options :scale 1.1)
(plist-put org-format-latex-options :foreground nil)
(plist-put org-format-latex-options :background nil)
;; 'auto currently inherits from hl-line
;; can add a hook to modus-themes-toggle
;; global version of:
;; :PROPERTIES:
;; :COOKIE_DATA: recursive todo
;; :END:
(setq org-hierarchical-todo-statistics nil)
;; makes any internal file link open in same window
;; defualt value is find-file-other-window
;; changed for use in org-roam
(setf (cdr (assoc 'file org-link-frame-setup)) 'find-file)
(setq org-return-follows-link t)
;; agenda
;; https://github.com/rougier/emacs-gtd
(setq org-agenda-files (list "~/personal/inbox.org"))
(setq org-capture-templates
`(("i" "Inbox" entry (file "~/personal/inbox.org")
,(concat "* %?\n" "/Entered on/ %U"))))
(defun jf/org-capture-inbox ()
(interactive)
(call-interactively 'org-store-link)
(org-capture nil "i"))
(defun jf/org-capture-inbox-note ()
(interactive)
(call-interactively 'org-store-link)
(org-capture nil "I"))
(setq org-refile-targets `(("~/personal/projects.org" :regexp . ,(regexp-opt '("Tasks")))))
(setq org-refile-use-outline-path 'file)
(setq org-outline-path-complete-in-steps nil)
(setq org-use-fast-todo-selection 'expert)
(setq org-todo-keywords
'((sequence "TODO(t)" "NEXT(n)" "HOLD(h)" "|" "DONE(d)" "DISC(z)")))
;; org-todo-keyword-faces set in jf/modus-themes-custom-faces
(setq org-log-done 'time)
(setq org-priority-highest 1
org-priority-default 3
org-priority-lowest 5)
(setq org-agenda-span 5)
(setq org-agenda-time-grid
(quote
((daily today require-timed)
(600 800 1000 1200 1400)
" ⊢" "――――")))
(setq org-agenda-sorting-strategy
'((agenda habit-down time-up priority-down category-keep)
(todo priority-down category-keep)
(tags priority-down tag-up category-keep)
(search category-keep)))
(setq org-agenda-custom-commands
'(("g" "Get Things Done (GTD)"
((agenda ""
(;; (org-agenda-skip-function
;; '(org-agenda-skip-entry-if 'deadline))
(org-deadline-warning-days 0)))
(todo "NEXT"
(;; (org-agenda-skip-function
;; '(org-agenda-skip-entry-if 'deadline))
(org-agenda-prefix-format " %i %-12:c [%e] ")
(org-agenda-overriding-header "\nNext Tasks\n")))
(todo "HOLD"
(;; (org-agenda-skip-function
;; '(org-agenda-skip-entry-if 'deadline))
(org-agenda-prefix-format " %i %-12:c [%e] ")
(org-agenda-overriding-header "On Hold\n")))
;; (agenda nil
;; ((org-agenda-entry-types '(:deadline))
;; ;; (org-agenda-format-date "")
;; (org-deadline-warning-days 7)
;; ;; https://github.com/rougier/emacs-gtd/issues/21
;; (org-agenda-show-all-dates nil)
;; (org-agenda-skip-function
;; '(org-agenda-skip-entry-if 'notregexp "\\* NEXT"))
;; (org-agenda-overriding-header "\nDeadlines")))
(tags-todo "projects"
((org-agenda-skip-function
'(org-agenda-skip-entry-if 'todo '("NEXT" "HOLD")))
(org-agenda-prefix-format " %?-12t% s")
(org-agenda-overriding-header "\nProjects\n")))
(tags-todo "+inbox+TODO=\"TODO\""
((org-agenda-prefix-format " %?-12t% s")
(org-agenda-overriding-header "\nInbox\n")))
;; (tags "+CLOSED>=\"<today>\""
;; ((org-agenda-overriding-header "\nCompleted today\n")))
;; 230105: for some reason <today> isn't working
;; https://www.reddit.com/r/emacs/comments/75nkj6/orgmode_tasks_closed_yesterday/do85ili/
(tags (concat "+TODO=\"DONE\"+CLOSED>="
(prin1-to-string (format-time-string "[%Y-%m-%d]" (current-time))))
((org-agenda-overriding-header "\nCompleted today\n")))
))
("w" "Completed tasks from previous week"
((agenda "" ((org-agenda-span 7)
(org-agenda-start-day nil)
(org-agenda-skip-function
'(org-agenda-skip-entry-if 'nottodo '("DONE")))
(org-agenda-prefix-format " %? s")
(org-agenda-show-log t)))))))
;; make mastodon and org agenda bookmark-able to some degree
;; https://github.com/alphapapa/activities.el/issues/19#issuecomment-1925700528
;; alternatively, look into replacing agenda with org-ql
(defun jf/agenda-bookmark (_bookmark)
(org-agenda nil "g"))
(add-hook 'org-agenda-mode-hook
(lambda ()
(setq-local bookmark-make-record-function
(lambda ()
`((handler . jf/agenda-bookmark))))))
:bind
(("C-c a" . #'org-agenda)
("C-c c" . #'org-capture)
("C-c i" . #'jf/org-capture-inbox)
("C-c I" . #'jf/org-capture-inbox-note)
;; View closed tasks from last Monday to now
;; superseded by org-agenda w
;; ("C-c w" . (lambda () (interactive)
;; (org-tags-view nil
;; (concat "+TODO=\"DONE\"+CLOSED>="
;; (prin1-to-string (substring
;; (shell-command-to-string "date -dlast-monday +[%Y-%m-%d]") 0 -1))))))
:map org-mode-map
("$" . #'math-delimiters-insert)
("C-c C-x d" . #'org-metadown)
;; org-agenda-mode-map is not loading on startup for some reason
;; :map org-agenda-mode-map
;; ("g" . #'org-agenda-redo)
;; ("r" . #'org-agenda-redo-all)
)
:hook
(org-mode . org-indent-mode)
(org-agenda-mode . (lambda () (buffer-face-set :height 120))))
(use-package org-fragtog
:init
(add-hook 'org-mode-hook 'org-fragtog-mode))
;; (use-package org-modern
;; :config
;; (setq org-modern-hide-stars 'leading
;; org-modern-horizontal-rule nil ;; not sure what this is
;; org-modern-internal-target '(" ↪ " nil " ")
;; org-modern-keyword "≽"
;; org-modern-priority nil
;; org-modern-progress nil
;; org-modern-radio-target nil
;; org-modern-star nil
;; org-modern-statistics nil
;; org-modern-table-horizontal 10 ;; this is not centered
;; org-modern-table-vertical 2
;; org-modern-tag nil
;; org-modern-todo nil)
;; ;; :hook
;; ;; (org-mode . org-modern-mode)
;; (global-org-modern-mode)
;; )
;;;; Org Export - LaTeX
;; https://blog.tecosaur.com/tmio/2022-05-31-folding.html#-engraved-source
;; using https://wiki.archlinux.org/title/TeX_Live#tllocalmgr
;; Check on alternative: https://www.reddit.com/r/emacs/comments/lbkmmz/the_best_syntax_highlighting_in_a_pdf_youll_see_a/
(setq org-latex-src-block-backend 'engraved)
(setq org-latex-compiler "xelatex")
;; Need to run multiple times to collapse any missed references
;; https://tex.stackexchange.com/a/38076
;; (setq org-latex-pdf-process '("latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f -shell-escape"
;; "latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f -shell-escape"
;; "latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f -shell-escape"))
;; fontspec needs xelatex or lualatex
;; https://tex.stackexchange.com/questions/264461/xelatex-minted-code-block-represents-tabs-as-i
;; -8bit because minted blocks insert a '^^I' on line break indents
;; look at "breaksymbolleft" in minted manual for more.
(setq org-latex-pdf-process '("latexmk -f -pdfxe -xelatex=\"xelatex -8bit\" -interaction=nonstopmode -output-directory=%o %f -shell-escape"
"latexmk -f -pdfxe -xelatex=\"xelatex -8bit\" -interaction=nonstopmode -output-directory=%o %f -shell-escape"
"latexmk -f -pdfxe -xelatex=\"xelatex -8bit\" -interaction=nonstopmode -output-directory=%o %f -shell-escape"))
;; for some reason, setting fonts does not work when in org-latex-classes
;; need to add manual LATEX_HEADER
;; #+LATEX_HEADER: \usepackage{fontspec}
;; #+LATEX_HEADER: \setmainfont[]{IBM Plex Sans}
;; #+LATEX_HEADER: \setmonofont[]{Iosevka Custom}
;; TODO: Remove minted after, since using engraved-faces
(setq org-latex-classes '(("article" "\\documentclass[11pt]{article}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
("report" "\\documentclass[11pt]{report}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
("book" "\\documentclass[11pt]{book}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
("notes"
"\\documentclass[8pt]{article}
\\usepackage[letterpaper, portrait, margin=1in]{geometry}
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{amsmath}
\\usepackage{amssymb}
\\usepackage{hyperref}
\\hypersetup{colorlinks=true}
% autoloaded with engraved-faces:
% \\usepackage{tcolorbox}
% http://tug.ctan.org/macros/latex/contrib/minted/minted.pdf
\\usepackage[cache=false]{minted}
\\setminted{breaklines=true, breakanywhere=true}
% \\usemintedstyle{paraiso-light} % pygmentize -L styles
% \\usemintedstyle{emacs} % pygmentize -L styles
% \\usemintedstyle{colorful} % pygmentize -L styles
% \\usemintedstyle{rainbow_dash} % pygmentize -L styles
\\usemintedstyle{tango} % pygmentize -L styles
% https://tex.stackexchange.com/questions/112559/box-around-minted-environment
% https://ctan.math.utah.edu/ctan/tex-archive/macros/latex/contrib/tcolorbox/tcolorbox.pdf
\\BeforeBeginEnvironment{minted}{\\begin{tcolorbox}[colframe=black!85!white, colback=black!5!white, boxrule=0.3mm]}
\\AfterEndEnvironment{minted}{\\end{tcolorbox}}
\\usepackage{enumitem}
\\setitemize{itemsep=0.5pt}
\\usepackage{fancyhdr}
\\pagestyle{fancy}
\\fancyhf{}
\\usepackage{titling} % allows \thetitle \theauthor \thedate
\\usepackage{lastpage}
\\rhead{\\theauthor}
\\lhead{\\thetitle}
% Disable pageref being a link https://tex.stackexchange.com/a/4599
\\rfoot{\\thepage{} of \\pageref*{LastPage}}
\\linespread{1}
\\setlength{\\parindent}{0pt}
\\setlength{\\parskip}{0.5em plus 0.1em minus 0.2em}
\\hypersetup{pdfborder=0 0 0}
\\setcounter{secnumdepth}{0}
% \\usepackage{fontspec}
% \\setmainfont[]{IBM Plex Sans}
% \\setmonofont[]{Iosevka Custom}
"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
;;; edit-indirect
(use-package edit-indirect)
;;; Markdown-mode
(use-package markdown-mode
:config
(setq markdown-unordered-list-item-prefix " - ")
(markdown-toggle-fontify-code-blocks-natively 1)
:bind (:map markdown-mode-map
("M-p" . nil)
("M-n" . nil))
:hook (markdown-mode . mixed-pitch-mode))
;;; Denote
(defvar prot-dired--limit-hist '()
"Minibuffer history for `prot-dired-limit-regexp'.")
;;;###autoload
(defun prot-dired-limit-regexp (regexp omit)
"Limit Dired to keep files matching REGEXP.
With optional OMIT argument as a prefix (\\[universal-argument]),
exclude files matching REGEXP.
Restore the buffer with \\<dired-mode-map>`\\[revert-buffer]'."
(interactive
(list
(read-regexp
(concat "Files "
(when current-prefix-arg
(propertize "NOT " 'face 'warning))
"matching PATTERN: ")
nil 'prot-dired--limit-hist)
current-prefix-arg))
(dired-mark-files-regexp regexp)
(unless omit (dired-toggle-marks))
(dired-do-kill-lines))
(use-package denote
:init
(denote-rename-buffer-mode 1)
:config
(setq denote-file-type 'org ; same as default
denote-directory (substitute-in-file-name "$HOME/denote-notes")
denote-dired-directories (list denote-directory)
denote-prompts '(title keywords))
(setq denote-templates '((reference . "TEXT\n\n\n* Resources\n - LINK")
(journal . "Today ")
(thoughts . "I ")))
(setq xref-search-program 'ripgrep) ; denote-link-backlinks uses xref
(setq denote-excluded-directories-regexp "docs\\|journal\\|scripts\\|bibliography\\|ltximg")
(setq denote-rename-buffer-format "[Δ] %t%b")
(setq denote-rename-buffer-backlinks-indicator " (←)")
:bind (("C-c n l" . #'denote-link-or-create) ; safe link insertion
("C-c n f" . #'denote-open-or-create) ; safe note creation
("C-c n b" . #'denote-backlinks)
("C-c n s" . #'denote-find-link) ; completing-read on links in buffer
("C-c n S" . #'denote-find-backlink) ; completing-read on backlinks to buffer
("C-c n r" . #'prot-dired-limit-regexp)
("C-c n c" . #'denote-rename-file-using-front-matter) ; update file name when modifying front-matter
("C-c n d" . (lambda () (interactive) (progn (dired denote-directory) (dired-hide-details-mode))))
("C-c n j" . #'denote-journal-extras-new-or-existing-entry))
:hook
(dired-mode . denote-dired-mode-in-directories))
(use-package denote-journal-extras
:after denote
:ensure nil
:config
(setq denote-journal-extras-title-format "%y%m%d"))
;;; citar
(use-package citar
:config
(setq citar-notes-paths (list denote-directory))
(add-to-list 'citar-file-open-functions '("pdf" . citar-file-open-external))
:custom
(citar-bibliography '("~/denote-notes/bibliography/my_library.bib"))
:hook
(LaTeX-mode . citar-capf-setup)
(org-mode . citar-capf-setup))
(use-package citar-embark
:after citar embark
:no-require
:config (citar-embark-mode))
;;; citar-denote
(use-package citar-denote
:config (citar-denote-mode))
;;; Org-transclusion
(use-package org-transclusion
:bind ("<f8>" . org-transclusion-add))
;;; Org-babel
(use-package org
:ensure nil
:config (org-babel-do-load-languages
'org-babel-load-languages '((R . t)
(shell . t)
(python . t)
(julia . t)))
(setq org-confirm-babel-evaluate nil))
;;; pdf-tools
(defun jf/zathura-current-pdf ()
(interactive)
(call-process "zathura" nil 0 nil (buffer-file-name)))
(use-package pdf-tools
:init
(setq pdf-view-midnight-colors '("#ffffff" . "#000000"))
(setq pdf-view-use-scaling t)
(pdf-tools-install)
:hook
(pdf-view-mode . auto-revert-mode)
:bind (:map pdf-view-mode-map
("C-c o" . #'jf/zathura-current-pdf)))
;;; AucTeX
(use-package tex
:defer t
:ensure auctex
:config
(setq TeX-auto-save t)
(setq TeX-electric-math (cons "\\(" "\\)"))
(add-to-list 'TeX-view-program-selection '(output-pdf "Zathura"))
(setq tex-chktex-program nil)
:hook
(LaTeX-mode . (lambda () (flycheck-mode -1))))
;;; elfeed (w/ arxiv)
(defun concatenate-authors (authors-list)
"Given AUTHORS-LIST, list of plists; return string of all authors concatenated.
https://cundy.me/post/elfeed/"
(mapconcat
(lambda (author) (car (last (split-string ; get last names
(plist-get author :name)))))
authors-list ", "))
(defun my-search-print-fn (entry)
"Print ENTRY to the buffer."
(let* ((elfeed-search-date-format '("%m-%d" 5 :left))
(date (elfeed-search-format-date (elfeed-entry-date entry)))
(title (or (elfeed-meta entry :title)
(elfeed-entry-title entry) ""))
(title-faces (elfeed-search--faces (elfeed-entry-tags entry)))
(feed (elfeed-entry-feed entry))
(feed-title
(when feed
(or (elfeed-meta feed :title) (elfeed-feed-title feed))))
(entry-authors (concatenate-authors
(elfeed-meta entry :authors)))
(tags (mapcar #'symbol-name (elfeed-entry-tags entry)))
(tags-str (mapconcat
(lambda (s) (propertize s 'face
'elfeed-search-tag-face))
tags ","))
(title-width (- (window-width) 10
elfeed-search-trailing-width))
(title-column (elfeed-format-column
title 100
;; (elfeed-clamp
;; elfeed-search-title-min-width
;; title-width
;; elfeed-search-title-max-width)
:left))
(authors-width 35)
(authors-column (elfeed-format-column
entry-authors (elfeed-clamp
elfeed-search-title-min-width
authors-width
35)
:left)))
(insert (propertize date 'face 'elfeed-search-date-face) " ")
(insert (propertize title-column
'face title-faces 'kbd-help title) " ")
(insert (propertize authors-column
'face 'elfeed-search-date-face
'kbd-help entry-authors) " ")
;; (when feed-title
;; (insert (propertize entry-authors
;; 'face 'elfeed-search-feed-face) " "))
;; (when entry-authors
;; (insert (propertize feed-title
;; 'face 'elfeed-search-feed-face) " "))
(when tags
(insert "(" tags-str ")"))))
(use-package elfeed
;; https://www.reddit.com/r/emacs/comments/ufvg93/my_phd_research_workflowemacs_inside/
:init
(defun make-arxiv-url (category)
"https://arxiv.org/category_taxonomy."
(let ((base "http://export.arxiv.org/api/query?search_query=cat:")
;; (cat "cond-mat.mtrl-sci")
(range "&start=0&max_results=100&sortBy=submittedDate&sortOrder=descending")
(sort-by "&sortBy=submittedDate")
(sort-order "&sortOrder=descending"))
(concat base category range sort-by sort-order)))
;; TODO can use ar5iv for html render (view in browser)
;; Usually lags behind a few months
;; Can do locally with https://github.com/dginev/ar5ivist
;; https://ar5iv.labs.arxiv.org/html/2302.00011
(defun jf/download-arxiv ()
"Download pdf of current elfeed-entry."
(interactive)
(let* ((url (elfeed-entry-link elfeed-show-entry))
(pdf-url (s-replace "abs" "pdf" url))
(id (car (last (s-split "/" url))))
(pdf-path (concat arxiv-dir id ".pdf")))
(if (file-exists-p pdf-path)
(find-file pdf-path)
(progn (url-copy-file pdf-url pdf-path)
(find-file pdf-path)))))
:config (setq elfeed-feeds `(
(,(make-arxiv-url "cond-mat.mtrl-sci") matsci)
(,(make-arxiv-url "cond-mat.mes-hall") matsci theory)
(,(make-arxiv-url "stat.TH") stats theory)
(,(make-arxiv-url "stat.AP") stats appl)
(,(make-arxiv-url "stat.ME") stats appl)))
(setq-default elfeed-search-filter "@3-days-ago +unread ")
;; I have no idea how much I need to change these vars
(setq elfeed-search-trailing-width 30)
(setq elfeed-search-title-max-width 80)
(setq elfeed-search-print-entry-function #'my-search-print-fn)
:hook
(elfeed-show-mode . mixed-pitch-mode)
(elfeed-show-mode . olivetti-mode)
:bind
("C-c e" . #'elfeed)
(:map elfeed-search-mode-map
("n" . #'next-logical-line)
("p" . #'previous-logical-line))
(:map elfeed-show-mode-map
("o" . 'jf/download-arxiv)))
;;; Programming
(use-package helpful
:bind (("C-h f" . #'helpful-callable)
("C-h v" . #'helpful-variable)
("C-h k" . #'helpful-key)