-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.el
8761 lines (8005 loc) · 331 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
;;; init.el --- Emacs configuration for Jeremy Friesen -*- lexical-binding: t; -*-
;;
;;; Commentary:
;;
;; This is my journey into Emacs. Let's see where we go! I have tried
;; `org-mode' literate configuration, separate conceptual files, and am
;; now creating a singular unholy init file of all the things. I have
;; made efforts to associate the functions/variables with their
;; corresponding packages; either built-in or from places such as
;; melpa.
;;
;; How is this mess organized? I have favored the `use-package' macro
;; to fit most of the configuration within the `use-package' sexp.
;; This has meant using several built-in packages, which provides some
;; organizational meaning. And as I get more familiar with those
;; built-in packages, I can begin to explore their configurability.
;;
;; This organization does mean that I'm declaring a function within the
;; `use-package' macro that might depend on other packages. Perhaps
;; overtime I'll refactor accordingly.
;;
;;; Code:
(add-to-list 'load-path "~/git/dotemacs/emacs.d")
;; Let's just shunt those custom files into oblivion.
(setq custom-file (make-temp-file "emacs-custom-"))
(load custom-file :noerror)
;; https://www.reddit.com/r/emacs/comments/mtb05k/emacs_init_time_decreased_65_after_i_realized_the/
(setq straight-check-for-modifications
'(check-on-save find-when-checking))
;; This preamble is part of straight-use-package My understanding, in
;; reading straight documentation is that it has better load
;; times. However, the configuration options I often see leverage
;; "use-package" which is why most of my package declarations look as
;; they do.
(defvar bootstrap-version nil)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el"
user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(setq straight-repository-branch "develop")
(straight-use-package 'use-package)
(setq use-package-always-ensure t)
;; See https://github.com/radian-software/straight.el/issues/1146
(use-package straight
:custom
;; add project and flymake to the pseudo-packages variable so straight.el doesn't download a separate version than what eglot downloads.
(straight-built-in-pseudo-packages '(emacs nadvice python image-mode project flymake))
(straight-use-package-by-default t))
;; When you open Emacs, grab all the space on the screen
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
(use-package gcmh
;; *Gcmh* does garbage collection (GC) when the user is idle.
:straight t
:init
(setq
gcmh-idle-delay 5
gcmh-low-cons-threshold (* 1024 1024)
gcmh-high-cons-threshold (* 16 1024 1024))
:config (gcmh-mode)
(add-function :after after-focus-change-function
(defun jf/garbage-collect-maybe ()
(unless (frame-focus-state)
(garbage-collect)))))
(use-package emacs
;; Setting baseline behavior for Emacs.
:straight (:type built-in)
:init
;; And I’m going to disable a few key bindings. These were always
;; messing me up a bit. Also enable a few that I find helpful. (I’ll
;; enable a lot more later).
(unbind-key "C-z") ;; `suspend-frame'
(unbind-key "s-o") ;; `ns-open-file-using-panel'
(unbind-key "C-x C-c") ;; `save-buffers-kill-terminal'
;; Hide the icons of the Emacs toolbar
(tool-bar-mode -1)
;; Ensuring I have an autosave directory. On a few rare occassions
;; this has saved me from lost "work".
(make-directory "~/.emacs.d/autosaves/" t)
:bind (("M-[" . #'backward-paragraph)
("s-[" . #'backward-paragraph)
("H-s". #'save-buffer)
("M-]" . #'forward-paragraph)
("s-]" . #'forward-paragraph)
("C-k" . #'jf/kill-line-or-region)
("C-c n" . #'jf/yank-file-name-to-clipboard) ;; Deprecated
("C-c y n" . #'jf/yank-file-name-to-clipboard)
("M-<delete>" . #'kill-word)
("s-<down>" . #'end-of-buffer)
("s-<up>" . #'beginning-of-buffer)
("s-q" . #'save-buffers-kill-terminal)
("s-w" . #'kill-current-buffer)
("s-i" . #'ibuffer)
("M-RET" . #'newline-and-indent))
:bind (:map emacs-lisp-mode-map
("C-c C-c" . 'jf/eval-region-dwim))
:config
;; Allow "y" or "n" to stand in for yes/no prompts
(defalias 'yes-or-no-p 'y-or-n-p)
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; With 80 columns, I can always have two windows side-by-side.
(setq-default fill-column 80)
;; Doing a bit of configuration of my cursors. The blinking provides
;; the queue and on 2024-05-18, I thought I'd give a try with the
;; hollow box. Why? It feels more retro.
(setq-default cursor-type 'bar)
(blink-cursor-mode t)
(setq
;; Don't delink hardlinks
backup-by-copying t
;; On a few occassions, perhaps once every three months, I dive into
;; my backups to find something that 1) wasn't under version control
;; and 2) somehow got altered.
backup-directory-alist '((".*" . "~/.emacs.d/backups/"))
;; I may as well trust themes.
custom-safe-themes t
;; Don't create lock files. It's only me on this machine...I hope.
create-lockfiles nil
;; Instead of delete being gone forever, throw it in the trashbin
;; which I must take out
delete-by-moving-to-trash t
;; Automatically delete excess backups
delete-old-versions t
global-mark-ring-max 32
help-window-select t
;; Show index and count of search results
isearch-lazy-count t
lazy-count-prefix-format "(%s/%s) "
;; Slow down the UI being updated to improve performance
idle-update-delay 0.5
;; Ensure tabs are expanded, not inserted
indent-tabs-mode nil
;; Don't include the emacs "start" window
inhibit-startup-screen t
;; how many of the newest versions to keep
kept-new-versions 20
;; and how many of the old
kept-old-versions 5
;; Set a generous kill ring size.
kill-ring-max 128
;; Favor new bit code
load-prefer-newer t
;; Increase read size per process
read-process-output-max (* 6 512 1024)
require-final-newline t
;; Make regular Isearch interpret empty space as regular expression
;; search-whitespace-regexp ".*?"
;; Type C-u C-SPC to pop the mark, then C-SPC to pop again.
;; Without this variable, it's C-u C-SPC everytime
set-mark-command-repeat-pop t
show-trailing-whitespace t
;; https://www.masteringemacs.org/article/demystifying-emacs-window-manager
switch-to-buffer-obey-display-actions t
;; https://github.com/maryrosecook/emacs/blob/6ef574e27f33f08a81b26970b5fb9b4c9c1f9eff/init.el#L745
;; make emacs only add vertical split panes
;; split-height-threshold 99999999999999999
;; Follow symlinks instead of prompting.
vc-follow-symlinks t
;; Use version numbers on backups
version-control t
;; Recommendation from https://protesilaos.com/emacs/modus-themes
x-underline-at-descent-line t
line-move-visual t)
;; These are some general configurations that I’ve slowly accumulated.
;; There’s inline documentation in most cases. There might be little
;; bits worth teasing out but for the most part, you can move along
;; and reference this later.
(setq user-full-name "Jeremy Friesen"
user-mail-address "jeremy@jeremyfriesen.com")
(defun jf/alist-prompt (prompt collection &rest args)
"PROMPT from an alist COLLECTION returning a `cons'.
This is a simple wrapper around the `completing-read' function."
(let ((string (completing-read prompt collection args)))
(cons string (alist-get string collection nil nil #'string=))))
(defun jf/eval-region-dwim ()
"When region is active, evaluate it and kill the mark.
Else, evaluate the whole buffer."
;; I try to get quick feedback when writing emacs-lisp; the
;; `jf/eval-region-dwim' binds a mnemonic key sequence to an extend
;; `eval-region'.
(interactive)
(if (not (region-active-p))
(progn
(message "Evaluating buffer...")
(eval-buffer))
(progn
(message "Evaluating region...")
(eval-region (region-beginning) (region-end)))
(setq-local deactivate-mark t)))
(defun jf/kill-line-or-region (&optional arg)
"Kill the selected region otherwise kill the ARG number of lines."
(interactive "P")
(if (use-region-p)
(kill-region (region-beginning) (region-end))
(kill-line arg)))
;; The following function facilitates a best of both worlds. By
;; default, I want Option to be Meta (e.g. \"M-\") in Emacs.
;; However, I can toggle that setting. That way if I need an umlaut
;; (e.g., \"¨\"), I can use MacOS’s native functions to type \"⌥\" +
;; \"u\".
;;
;; I like having MacOS’s native Option (e.g. =⌥=) modifier
;; available. But using that default in Emacs would be a
;; significant hinderance.
(defun jf/toggle-osx-alternate-modifier ()
"Toggle native OS-X Option modifier setting.
See `ns-alternate-modifier'."
(interactive)
(if ns-alternate-modifier
(progn (setq ns-alternate-modifier nil)
(message "Enabling OS X native Option modifier"))
(progn (setq ns-alternate-modifier 'meta)
(message "Disabling OX X native Option modifier"))))
;; Exposing one additional modifier key. This opens up a significant
;; set of keys and no one (by default) binds to 'H-' while many bind
;; to 'C-c' or other 'C-' keys, leaving conflicts.
(setq ns-right-command-modifier 'hyper
ns-right-alternate-modifier 'meta)
(defun jf/yank-file-name-to-clipboard (arg)
"Nab, I mean copy, the current buffer file name to the clipboard.
When you pass one universal prefix ARG, nab the project
relative filename. When you pass two or more prompt for
different aspects of a file."
;; https://blog.sumtypeofway.com/posts/emacs-config.html
(interactive "P")
(let* ((prefix
(car arg))
(raw-filename
(if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name)))
(filename
(cond
((not prefix)
raw-filename)
((= prefix 4)
(concat "./"
(file-relative-name
raw-filename (projectile-project-root))))
((>= prefix 16)
(let ((options
'(("Filename, Basename" .
(lambda (f) (file-name-nondirectory f)))
("Filename, Project Relative" .
(lambda (f)
(concat "./"
(file-relative-name f
(projectile-project-root)))))
("Filename, Full" .
(lambda (f) (f)))
("Dirname" .
(lambda (f) (file-name-directory f)))
("Dirname, Project Relative" .
(lambda (f)
(concat "./"
(file-relative-name
(file-name-directory f)
(projectile-project-root))))))))
(funcall
(alist-get
(completing-read "Option: " options nil t)
options nil nil #'string=)
raw-filename))))))
(when filename
(kill-new filename)
(message
"Copied buffer file name '%s' to the clipboard."
filename)))))
(use-package subword
;; With subword-mode, HelloWorld is two words for navigation.
:straight (:type built-in)
:config
(global-subword-mode))
(use-package exec-path-from-shell
;; https://xenodium.com/trying-out-gccemacs-on-macos/
:straight t
:config
(exec-path-from-shell-initialize)
(if (and (fboundp 'native-comp-available-p)
(native-comp-available-p))
(progn
(message "Native comp is available")
;; Using Emacs.app/Contents/MacOS/bin since it was compiled with
;; ./configure --prefix="$PWD/nextstep/Emacs.app/Contents/MacOS"
(add-to-list 'exec-path (concat invocation-directory "bin") t)
(setenv "LIBRARY_PATH"
(concat (getenv "LIBRARY_PATH")
(when (getenv "LIBRARY_PATH")
":")
;; This is where Homebrew puts gcc libraries.
(car (file-expand-wildcards
"/opt/homebrew/lib/gcc/*"))))
;; Only set after LIBRARY_PATH can find gcc libraries.
(setq comp-deferred-compilation t))
(message "Native comp is *not* available")))
(use-package recentf
;; The probability of me needing to open a file I "recently" opened is
;; high. Providing a list of those files for easy searching helps me
;; navigate tasks that I'm working on over the course of a week or
;; more.
:straight (:type built-in)
:config
(setq recentf-max-menu-items 50
recentf-max-saved-items 256)
;; Track recent
(recentf-mode 1)
;; Quietly save the recent file list every 10 minutes.
(run-at-time nil 600 (lambda ()
(let ((save-silently t))
(recentf-save-list)))))
(use-package autorevert
:straight (:type built-in)
:config
(global-auto-revert-mode))
(use-package grep
;; The most important switch is moving from 'grep' to 'ripgrep', a
;; fast near drop-in replacement for 'grep'; most notable on large
;; directories.
:straight (:type built-in)
:config
(when (executable-find "rg")
(setq grep-program "rg")))
(defun jf/sort-unique-lines (reverse beg end
&optional adjacent
keep-blanks
interactive)
"Sort lines and delete duplicates.
By default the sort is lexigraphically ascending. To sort as
descending set REVERSE to non-nil. Specify BEG and END for the
bounds of sorting. By default, this is the selected region.
I've included ADJACENT, KEEP-BLANKS, and INTERACTIVE so I can
echo the method signature of `sort-lines' and
`delete-duplicate-lines'"
(interactive "P\nr")
(sort-lines reverse beg end)
(delete-duplicate-lines
beg end reverse adjacent keep-blanks interactive))
(use-package ediff
;; I haven't used `ediff' much, but it's a good option for reviewing
;; file deltas.
:straight (:type built-in)
:config
(setq ediff-keep-variants nil)
(setq ediff-make-buffers-readonly-at-startup nil)
(setq ediff-merge-revisions-with-ancestor t)
(setq ediff-show-clashes-only t)
(setq ediff-split-window-function 'split-window-horizontally)
(setq ediff-window-setup-function 'ediff-setup-windows-plain))
(use-package dired
;; Oh `dired', you are a super powered directory editor. For years I
;; avoided interacting with you, but overtime I've practiced and find
;; your utility great. Never conflate a file with a buffer and
;; instead consider the power of what a buffer can do.
:straight (:type built-in)
:custom (dired-listing-switches "-laGhpX")
(dired-use-ls-dired t)
:config
;; When two dired buffers are open and you mark then rename a file, it
;; assume's you're moving the file from the one buffer to the other.
;; Very useful.
(setq dired-dwim-target t)
(setq dired-vc-rename-file t)
(with-eval-after-load 'dired
;; Bind dired-x-find-file.
(setq dired-x-hands-off-my-keys nil)
(require 'dired-x))
:hook (dired-mode . dired-hide-details-mode))
(use-package info
;; A lot of offline documentation resides in the venerable `info'
;; format. This allows me to access the info docs that are part of
;; brew installed packages.
:straight (:type built-in)
:config
(info-initialize)
(push "/opt/homebrew/share/info" Info-directory-list))
(use-package expand-region
;; A simple package that does two related things really well; expands
;; and contracts the current region. I use this all the time.
;;
;; In writing, with the cursor at point, when I expand it selects the
;; word. The next expand the sentence, then paragraph, then page. In
;; programming it leverages sexp.
:straight (:host github :repo "jeremyf/expand-region.el")
:bind (("C-=" . er/expand-region)
("C-+" . er/contract-region)))
(use-package display-fill-column-indicator
;; It's nice to have a gentle reminder showing me the recommended
;; column width for the current buffer.
:straight (:type built-in)
:hook (prog-mode . display-fill-column-indicator-mode))
(use-package kind-icon
;; This packages helps provide additional icons for functions and
;; variables in the completion candidates.
:straight t
:after corfu
:custom
(kind-icon-use-icons t)
;; Have background color be the same as `corfu' face background
(kind-icon-default-face 'corfu-default)
;; Use midpoint color between foreground and background colors
;; ("blended")?
(kind-icon-blend-background nil)
(kind-icon-blend-frac 0.08)
;; directory that defaults to the `user-emacs-directory'. Here, I
;; change that directory to a location appropriate to `no-littering'
;; conventions, a package which moves directories of other packages to
;; sane locations. (svg-lib-icons-dir
;; (no-littering-expand-var-file-name "svg-lib/cache/")) ; Change
;; cache dir
:config
;; Enable-Recursive-Minibuffers `kind-icon'
(add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
(use-package lin
;; “LIN locally remaps the hl-line face to a style that is optimal
;; for major modes where line selection is the primary mode of
;; interaction.” In otherwords, ~lin.el~ improves the highlighted
;; line behavior for the competing contexts.
:straight (lin :host gitlab :repo "protesilaos/lin")
:init (global-hl-line-mode)
:config (lin-global-mode 1)
(setq lin-face 'lin-blue))
(use-package pulsar
;; A little bit of visual feedback. See
;; https://protesilaos.com/codelog/2022-03-14-emacs-pulsar-demo/
:straight (pulsar :host gitlab :repo "protesilaos/pulsar")
:hook
(consult-after-jump . pulsar-recenter-top)
(consult-after-jump . pulsar-reveal-entry)
;; integration with the built-in `imenu':
(imenu-after-jump . pulsar-recenter-top)
(imenu-after-jump . pulsar-reveal-entry)
:config
(pulsar-global-mode 1)
(setq pulsar-face 'pulsar-magenta
pulsar-delay 0.05)
:bind (("C-c C-l" . jf/pulse)))
(defun jf/pulse (&optional parg)
"Pulse the current line.
When PARG pulse between `point' and `mark'."
(interactive "P")
(if (car parg)
(pulsar--pulse nil nil (point) (mark))
(pulsar-pulse-line)))
;; Silence that bell by pulsing the line instead
(setq ring-bell-function 'jf/pulse)
(use-package rainbow-mode
;; When I toggle on Rainbow mode, it colorizes the text that is color
;; names and hex declarations (e.g. "#0000ff" ). Most useful when
;; working with CSS, but sometimes non-CSS files have those
;; declarations as well.
:straight t)
(use-package rainbow-delimiters
;; A quick and useful visual queue for paranthesis.
:straight t
:hook (prog-mode-hook . rainbow-delimiters-mode))
(use-package recursion-indicator
;; I vascilate between yes and no; but invariably find myself stuck in
;; a recursed buffer.
:straight t
:demand t
:init
(setq enable-recursive-minibuffers t)
:config
(recursion-indicator-mode))
(use-package vi-tilde-fringe
;; Show tilde (e.g. ~\~~) on empty trailing lines. This is a feature
;; ported from https://en.wikipedia.org/wiki/Vi
:straight t
:config (global-vi-tilde-fringe-mode))
(use-package whole-line-or-region
;; From the package commentary, “This minor mode allows functions to
;; operate on the current line if they would normally operate on a
;; region and region is currently undefined.” I’ve used this for
;; awhile and believe it’s not baked into my assumptions regarding how
;; I navigate Emacs.
:straight t
:config (whole-line-or-region-global-mode))
(use-package keycast
;; It can be helpful when pairing or presenting to have a log of your
;; key cominations.
:straight t
:init
(setq keycast-mode-line-insert-after
'jf/mode-line-format/buffer-name-and-status)
(setq keycast-mode-line-remove-tail-elements nil)
(setq keycast-mode-line-window-predicate 'mode-line-window-selected-p)
(setq keycast-mode-line-format "%2s%k%2s(%c%R)"))
(use-package emacs
:straight (:type built-in)
:after (projectile)
:preface
(defvar-local jf/mode-line-format/kbd-macro
'(:eval
(when (and (mode-line-window-selected-p) defining-kbd-macro)
(propertize " KMacro " 'face 'mode-line-highlight))))
(defvar-local jf/mode-line-format/buffer-name-and-status
'(:eval
(let ((name
(buffer-name)))
(propertize
(if buffer-read-only
(format " %s %s " (char-to-string #xE0A2) name)
name)
'face
(if (mode-line-window-selected-p)
'mode-line-buffer-id
'mode-line-inactive)))))
(defun jf/mode-line-format/major-mode-indicator ()
"Return propertized mode line indicator for the major mode."
(let ((indicator
(cond
((derived-mode-p 'text-mode) "§")
((derived-mode-p 'prog-mode) "λ")
((derived-mode-p 'comint-mode) ">_")
(t "◦"))))
(propertize indicator
'face
(if (mode-line-window-selected-p)
'jf/mode-line-format/face-shadow
'mode-line-inactive))))
(defun jf/mode-line-format/major-mode-name ()
(propertize (capitalize
(string-replace "-mode" "" (symbol-name major-mode)))
'face (if (mode-line-window-selected-p)
'mode-line 'mode-line-inactive)))
(defvar-local jf/mode-line-format/major-mode
'(:eval
(concat
(jf/mode-line-format/major-mode-indicator)
" "
(jf/mode-line-format/major-mode-name))))
(defvar-local jf/mode-line-format/narrow
'(:eval
(when (and (mode-line-window-selected-p)
(buffer-narrowed-p)
(not (derived-mode-p
'Info-mode
'help-mode
'special-mode
'message-mode)))
(propertize " Narrow " 'face 'mode-line-highlight))))
(defvar jf/mode-line-format/vterm-map
(let ((map
(make-sparse-keymap)))
(define-key map [mode-line down-mouse-1] #'vterm-copy-mode)
map)
"Keymap to display on `vterm' copy indicator.")
(defvar-local jf/mode-line-format/vterm
'(:eval
(when (derived-mode-p 'vterm-mode)
(propertize
(concat " " (if vterm-copy-mode "©" "O") " ")
'face 'mode-line-highlight
'local-map jf/mode-line-format/vterm-map
'help-echo "mouse-1:vterm-copy-mode"))))
(defvar jf/mode-line-format/which-function-map
(let ((map
(make-sparse-keymap)))
(define-key map [mode-line mouse-1]
#'jf/yank-current-scoped-function-name)
(define-key map [mode-line M-mouse-1]
#'mark-defun)
map))
(defvar-local jf/mode-line-format/which-function
'(:eval
(when (and which-function-mode (mode-line-window-selected-p))
(when-let ((func (which-function)))
(propertize
(concat " ⨍ := " func)
'face
'mode-line-emphasis
'local-map
jf/mode-line-format/which-function-map
'help-echo
(concat
"mouse-1: #'jf/yank-current-scoped-function-name\n"
"M-mouse-1: #'mark-defun (C-M-h)"))))))
(defvar-local jf/mode-line-format/misc-info
'(:eval
(when (mode-line-window-selected-p)
mode-line-misc-info)))
(with-eval-after-load 'eglot
(setq mode-line-misc-info
(delete '(eglot--managed-mode
(" [" eglot--mode-line-format "] "))
mode-line-misc-info)))
(defvar-local jf/mode-line-format/eglot
`(:eval
(when (and (featurep 'eglot) (mode-line-window-selected-p))
'(eglot--managed-mode eglot--mode-line-format))))
(defvar-local jf/mode-line-format/vc-branch
'(:eval
(when-let* (((mode-line-window-selected-p))
(file
(if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name)))
(backend
(or (vc-backend file) 'git))
(branch
(jf/mode-line-format/vc-branch-name
file backend)))
(jf/mode-line-format/vc-details file branch))))
(defface jf/mode-line-format/face-shadow
'((t :foreground "#d0ffe0" :inherit shadow))
"A face for symbols in the `mode-line'.")
(defun jf/mode-line-format/vc-details (file branch)
"Return the FILE and BRANCH."
(propertize
(concat
;;
(propertize "" ;; (char-to-string #xE0A0)
'face
'jf/mode-line-format/face-shadow)
" "
branch)
'local-map jf/mode-line-format/map-vc
'help-echo "mouse-1: magit-status"))
(defvar jf/mode-line-format/map-vc
(let ((map
(make-sparse-keymap)))
(define-key map [mode-line down-mouse-1] #'magit-status)
map)
"Keymap to display on version control indicator.")
(defun jf/mode-line-format/vc-branch-name (file backend)
"Return VC branch name for FILE with BACKEND."
(when-let ((rev (vc-working-revision file backend))
(branch (or (vc-git--symbolic-ref file)
(substring rev 0 7))))
branch))
(defvar-local jf/mode-line-format/flymake
'(:eval
(when (and flymake--state
(mode-line-window-selected-p))
flymake-mode-line-format)))
(defvar-local jf/mode-line-format/project
'(:eval
(when (and (fboundp 'projectile-project-p) (projectile-project-p))
(propertize
(concat " " (project-name (project-current)))
'face
(if (mode-line-window-selected-p)
'jf/mode-line-format/face-shadow
'mode-line-inactive)))))
(dolist (construct '(
jf/mode-line-format/buffer-name-and-status
jf/mode-line-format/eglot
jf/mode-line-format/flymake
jf/mode-line-format/kbd-macro
jf/mode-line-format/major-mode
jf/mode-line-format/misc-info
jf/mode-line-format/narrow
jf/mode-line-format/project
jf/mode-line-format/vc-branch
jf/mode-line-format/vterm
jf/mode-line-format/which-function
))
(put construct 'risky-local-variable t))
(setq-default mode-line-format
'("%e" " "
jf/mode-line-format/vterm
jf/mode-line-format/kbd-macro
jf/mode-line-format/narrow
jf/mode-line-format/buffer-name-and-status " "
jf/mode-line-format/major-mode " "
jf/mode-line-format/project " "
jf/mode-line-format/vc-branch " "
jf/mode-line-format/flymake " "
jf/mode-line-format/eglot
jf/mode-line-format/which-function
;; jf/mode-line-format/misc-info
)))
(use-package ace-window
;; Quick navigation from window to window.
:straight t
:custom (aw-keys '(?a ?s ?d ?f ?g ?j ?h ?k ?l))
:bind (("M-o" . ace-window) ;; deprecated
("s-o" . ace-window)))
(use-package avy
;; Pick a letter, avy finds all words with that at the beginning of
;; it. Narrow results from there.
:bind (("C-j" . avy-goto-char-timer))
:straight t
:config
(setq avy-dispatch-alist
'((?. . jf/avy-action-embark)
(?x . avy-action-kill-move)
(?X . avy-action-kill-stay)
(?y . avy-action-yank)
(?Y . jf/avy-action-yank-whole-line)
(?w . avy-action-copy)
(?W . jf/avy-action-copy-whole-line)
(?k . avy-action-kill)
(?K . jf/avy-action-kill-whole-line)
(?t . avy-action-teleport)
(?T . jf/avy-action-teleport-whole-line)))
:config
;; https://karthinks.com/software/avy-can-do-anything/#remembering-to-avy
(defun jf/avy-action-kill-whole-line (pt)
(save-excursion
(goto-char pt)
(kill-whole-line))
(select-window
(cdr
(ring-ref avy-ring 0)))
t)
(defun jf/avy-action-copy-whole-line (pt)
(save-excursion
(goto-char pt)
(cl-destructuring-bind (start . end)
(bounds-of-thing-at-point 'line)
(copy-region-as-kill start end)))
(select-window
(cdr
(ring-ref avy-ring 0)))
t)
(defun jf/avy-action-yank-whole-line (pt)
(jf/avy-action-copy-whole-line pt)
(save-excursion (yank))
t)
(defun jf/avy-action-teleport-whole-line (pt)
(jf/avy-action-kill-whole-line pt)
(save-excursion (yank)) t)
(defun jf/avy-action-embark (pt)
(unwind-protect
(save-excursion
(goto-char pt)
(embark-act))
(select-window
(cdr (ring-ref avy-ring 0))))
t))
(use-package imenu-list
;; Show an outline summary of the current buffer.
:custom (imenu-list-focus-after-activation t)
(imenu-list-size 0.4)
(imenu-list-position 'right)
:bind ("s-4" . 'imenu-list-smart-toggle)
:bind (:map imenu-list-major-mode-map ("o" . 'imenu-list-goto-entry))
:straight t)
(use-package link-hint
;; I use this more and more and more. Invoking `link-hint-open-link'
;; highlights the visible URLs, providing quick keys to then open
;; those URLs. If there's only one candidate, the function opens that
;; URL.
:straight t
:bind
;; Note this is in the same prefix space as `browse-at-remote'
("C-c l o" . jf/link-hint-open-link)
("C-c l c" . link-hint-copy-link)
:config
(defun jf/link-hint-open-link (prefix)
"Hint at then browse a URL.
When given PREFIX use `eww-browse-url'."
(interactive "P")
(let ((browse-url-browser-function
(if prefix #'eww-browse-url browse-url-browser-function)))
(link-hint-open-link)))
(defun jf/link-hint--apply (advised-function func &rest args)
"Hijack opening `org-mode' URLs by attempting to open local file.
The ADVISED-FUNCTION is the original `link-hint--apply'.
The FUNC is the dispatched function for handling the link
type (e.g. `link-hint--open-org-link').
The ARGS are the rest of the ARGS passed to the ADVISED-FUNCTION."
(if (and
(eq 'link-hint--open-org-link func)
(eq :open (caddr args)))
(progn
(if-let* ((url
(car args))
(_match
(string-match
(concat "^https://github.com/"
"\\([^/]+\\)/\\([^/]+\\)" ;; org/repo
"/[^/]+/[^/]+/" ;; blob/sha
"\\([^#]+\\)" ;; path to fil
"\\(#L\\([0-9]+\\)\\)?") ;; line number
url)))
;; Due to my present file structure I have some repositories
;; in ~/git/ and others in ~/git/sub-dir
;;
;; In most every case, the Github org and repo match the
;; remote URL.
(let ((filename-without-org
(format "~/git/%s/%s"
(match-string 2 url)
(match-string 3 url)))
(filename-with-org
(format "~/git/%s/%s/%s"
(match-string 1 url)
(match-string 2 url)
(match-string 3 url)))
(line-number
(match-string 5 url)))
(cond
((f-exists? filename-without-org)
(progn
(find-file-other-window filename-without-org)
(when line-number
(goto-char (point-min))
(forward-line
(1- (string-to-number line-number))))))
((f-exists? filename-with-org)
(progn
(find-file-other-window filename-with-org)
(when line-number
(goto-char (point-min))
(forward-line
(1- (string-to-number line-number))))))
(t (funcall func args))))
(funcall func args)))
(apply advised-function func args)))
(advice-add 'link-hint--apply
:around #'jf/link-hint--apply))
;; Allow for opening the URLs provided in eldoc. This is rough and
;; minimal error handling.
(link-hint-define-type 'eldoc-url
:next #'link-hint--next-eldoc-url
:at-point-p #'link-hint--eldoc-url-at-point-p
:open #'browse-url
:copy #'kill-new)
(defun link-hint--next-eldoc-url (bound)
"Get position of next `face' at or after BOUND."
;; While we're interested in the 'help-echo value, we need to see if
;; we can't solely work from that. Instead we need to check if we
;; have a link face.
(link-hint--next-property-with-value 'face 'markdown-link-face bound))
(defun link-hint--eldoc-url-at-point-p ()
"Return the name of the eldoc link at the point or nil."
;; Mirroring `link-hint--next-eldoc-url' logic, when we have a link
;; face look to the help-echo for the URL.
(when (eq (get-text-property (point) 'face)
'markdown-link-face)
(get-text-property (point) 'help-echo)))
(push 'link-hint-eldoc-url link-hint-types)
(use-package browse-at-remote
;; Because I sometimes want to jump to the source code. And in
;; looking at this I learned about vc-annotate; a better blame than
;; what I've had before. `bar-browse' is faster than
;; `browse-at-remote'.
:straight t
:after (link-hint)
:bind
;; Note this is in the same prefix space as `link-hint'
("C-c l r" . browse-at-remote)
("C-c l a" . vc-annotate)
("C-c l n" . jf/project/jump-to/notes)
("C-c l t" . git-timemachine))
(use-package fontaine
;; A narrow focus package for naming font configurations and then
;; selecting them.
:straight t
:config
(setq fontaine-presets
;; I'm naming the presets as "actions"; the mindset that I'm using
;; when wanting that font.
'((smallest
:default-height 100)
(smaller
:default-height 120)
(default
:default-height 130)
(bigger
:default-height 160)
(coding
:default-family "IntoneMono Nerd Font Mono"
:default-weight light
:bold-weight medium
:default-height 130)
(biggest
:default-weight light
:default-height 220
:bold-weight bold)
(reading