summaryrefslogtreecommitdiff
path: root/jakob.org
blob: 71d2da81e71e92a3c5fadbff628c066f29b4ec3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
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
This file contains my personal Emacs configuration, done in the style of
literate programming. Of course, being myself, I have a natural tendency to go
against the grain and do everything /my/ way; rather than using the
functionality provided by =org-babel=, I've adapted a reimplementation of
=org-babel-tangle= to =eval-document= (see =init.el=), which "tangles" all of
the source blocks into a temporary buffer and proceed to evaluate that temporary
buffer. This doesn't have any noticeable implications, but it is worth noting
that there won't be a =jakob.el= in the Emacs configuration directory.

Custom elisp functions defined by me aren't prefixed with anything, with the
exception of functions that reimplement the functionality of existing functions.
These are prefixed with =my-= rather than replacing the original symbol, because
I imagine messing with built-in functionality in such a careless way would break
many things down the line.

* Vanilla Functionality

** Startup

Having Emacs open to =*scratch*= feels as if it's inviting me to punch out some
Lisp forms and evaluate them. I like to pretend that my computers are Lisp
machines.

#+BEGIN_SRC elisp
(setq inhibit-startup-message t
      inhibit-startup-buffer-menu t
      initial-scratch-message nil
      initial-buffer-choice nil)
#+END_SRC

** Filesystem

A recurring theme in this configuration file is reconfiguring where Emacs
packages drop their various state files. =no-littering.el= is a package that
handles this fairly well through the management of =~/.emacs.d/var/= and
=~/.emacs.d/etc/= directories, but it lacks defaults for enough packages that
I've decided to jut forego it and do things my way, placing things in =~/.cache=
and =~/.local/share=.

Save backup files to one directory instead of making a mess of the filesystem.

#+BEGIN_SRC elisp
(setq backup-directory-alist `(("." . "~/.cache/emacs")))
#+END_SRC

=auto-save=, in addition to the actual files it saves, maintains another file
listing the files it's currently taking care of.

#+BEGIN_SRC elisp
(setq auto-save-list-file-prefix "~/.cache/emacs/auto-save-list/.saves-")
#+END_SRC

Disables the creation of locking symlinks in the current directory. This is a
very opinionated choice, and might not be a good idea for the average user.

#+BEGIN_SRC elisp
(setq create-lockfiles nil)
#+END_SRC

Although I personally prefer writing elisp to =custom.el=, a few packages
(specifically =package.el=) do make use of it. This snippet ensures that a
massacre is not made of my =init.el=.

#+BEGIN_SRC elisp
(setq custom-file "~/.emacs.d/custom.el")
(when (file-exists-p custom-file)
  (load custom-file))
#+END_SRC

** Packages

For package archives, I currently use [[http://melpa.org/][MELPA]] and [[https://orgmode.org/elpa.html][Org's elpa]], the latter of which
is only enabled because Gentoo's Emacs package lacks =org-contribdir=.

#+BEGIN_SRC elisp
(require 'package)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize)
#+END_SRC

Bootstrapping for =use-package=, which is how I prefer to declare and configure
third-party packages.

#+BEGIN_SRC elisp
(unless (package-installed-p 'use-package)
  (progn
    (package-refresh-contents)
    (package-install 'use-package)))

(require 'use-package)
#+END_SRC

Ensure that packages are installed by default. This can be overridden in with
=:ensure nil=. The automatic installation functionality of =use-package= is the
main reason I use it, so why not enable it by default?

#+BEGIN_SRC elisp
(setq use-package-always-ensure t)
#+END_SRC

Require =bind-key= early on for =:bind= declarations.

#+BEGIN_SRC elisp
(use-package bind-key :defer t)
#+END_SRC

** Lisp Interaction

Don't omit information when lists nest too deep.

#+BEGIN_SRC elisp
(setq eval-expression-print-level nil)
#+END_SRC

** Quality of Life

Use a consistent confirmation dialog of "y or n".

#+BEGIN_SRC elisp
(fset 'yes-or-no-p 'y-or-n-p)
#+END_SRC

Automatically revert buffers and dired listings when something on disk changes.

#+BEGIN_SRC elisp
(use-package autorevert
  :config
  (global-auto-revert-mode 1)
  (setq global-auto-revert-non-file-buffers t
        auto-revert-verbose nil))
#+END_SRC

I got sick of seeing "Command attempted to use minibuffer while in minibuffer".

#+BEGIN_SRC elisp
(setq enable-recursive-minibuffers t)
#+END_SRC

Use soft wrapping instead of "scrolling" when overflowing the width of a frame.

#+BEGIN_SRC elisp
(global-visual-line-mode t)
#+END_SRC

Actually select help windows when I pop them so that I can kill them with <q>.

#+BEGIN_SRC elisp
(setq help-window-select t)
#+END_SRC

Most *NIX tools work best when files are terminated with a newline.

#+BEGIN_SRC emacs-lisp
(setq require-final-newline t)
#+END_SRC

Sentences should be separated by a single space, so treat two sentences as two
when filling.

#+BEGIN_SRC elisp
(setq sentence-end-double-space nil)
#+END_SRC

I like using the tab key, but prefer spaces to tabstops, and the width I prefer
to use is 4 characters.

#+BEGIN_SRC elisp
(setq-default indent-tabs-mode nil tab-width 4)
#+END_SRC

Modern conventions state that 80 characters is the standard width.

#+BEGIN_SRC elisp
(setq-default fill-column 80)
#+END_SRC

When killing, add whatever's in the system clipboard if it isn't there already,
so I can get it back with <M-y>.

#+BEGIN_SRC elisp
(setq save-interprogram-paste-before-kill t)
#+END_SRC

Enable the default-disabled functions that I use.

#+BEGIN_SRC elisp
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
#+END_SRC

#+BEGIN_SRC elisp
(show-paren-mode t)
(column-number-mode t)
#+END_SRC

* Appearance

** Windowing

This feature doesn't see frequent use, but I prefer three proportionally-sized
windows to two really tiny ones over a really big one.

#+BEGIN_SRC elisp
(setq window-combination-resize t)
#+END_SRC

** Scrolling

Don't do jerky jumps when the cursor reaches the end of the window. Instead,
just scroll by one line.

#+BEGIN_SRC elisp
(setq scroll-conservatively most-positive-fixnum)
#+END_SRC

** Chrome

The menu bar can be accessed with =M-`= if I really need it, so I don't see the
point in having it take up the space at the top. The rest of these rarely see
use from me, and I'd prefer to disable them and have access to the extra screen
real estate.

#+BEGIN_SRC elisp
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(fringe-mode -1)
#+END_SRC

Hacking is a lot more serene when visual stimulus is kept to a minimum.

#+BEGIN_SRC elisp
(blink-cursor-mode 0)
#+END_SRC

** Theme

This is my custom theme, the code for which is very loosely adapted from
[[https://github.com/kuanyui/moe-theme.el][moe-theme.el]], but most of the palette has been altered to emulate the appearance
of my old setup of Emacs in a terminal emulator.

#+BEGIN_SRC elisp
(deftheme chayote
  "Inspired by the appearance of Emacs in my terminal emulator.")
#+END_SRC

The colors have been extracted into a variable, =palette=, and a macro,
=with-palette=, to provide access to the theme's color definitions without
significantly polluting the global namespace.

#+BEGIN_SRC elisp
(defvar palette
  '((yellow-1 "#ffd787") (yellow-2 "#ffd700") (yellow-3 "#c4a000")
    (yellow-3-5 "#aaaa11") (yellow-4 "#875f00")

    (orange-1 "#ffaf87") (orange-2 "#ff8700") (orange-3 "#ff5d17")
    (orange-4 "#d75f00") (orange-5 "#af5f00")

    (magenta-1 "#ff7bbb") (magenta-2 "#ff4ea3") (magenta-3 "#ff1f8b")

    (green-1 "#87ff87") (green-2 "#a1db00") (green-3 "#5faf00")
    (green-4 "#008700") (green-5 "#005f00")

    (cyan-1 "#afd7d7") (cyan-2 "#87ffd7") (cyan-3 "#00d7af")
    (cyan-4 "#00ac8a") (cyan-5 "#5faf87") (cyan-6 "#005f5f")
    (cyan-7 "#236f73")

    (blue-1 "#1fb6d3") (blue-2 "#1f5bff") (blue-3 "#005f87")
    (blue-4 "#5f7ab1") (blue-5 "#0000af") (blue-6 "#00005f")

    (purple-1 "#d18aff") (purple-2 "#af5fff") (purple-3 "#9a08ff")
    (purple-4 "#6c0099")

    (red-1 "#ef2929") (red-2 "#dd0000") (red-3 "#a40000")
    (red-4 "#5f0000")

    (white-1 "#f0e9dc") (white-2 "#c6c6c6") (white-3 "#b2b2b2")

    (black-1 "#a8a8a8") (black-2 "#8a8a8a") (black-2-5 "#6c6c6c")
    (black-3 "#4e4e4e") (black-4 "#3a3a3a") (black-5 "#303539")
    (black-6 "#000000")

    (LIGHT_BG "#fdfde7") (white-0 "#eeeeee")

    (green-02 "#5fd700") (green-01 "#d7ff00") (green-0 "#d7ff5f")
    (green-00 "#d7ff87")

    (cyan-0 "#d7ffd7")

    (blue-01 "#c3c9f8") (blue-0 "#afd7ff") (blue-00 "#d7d7ff")

    (yellow-0 "#ffff87") (yellow-00 "#ffffaf")

    (purple-0 "#af87ff") (purple-00 "#e6a8df")

    (red-0 "#ff4b4b") (red-00 "#ffafaf")

    (magenta-0 "#ffafd7") (magenta-00 "#ffd7ff")

    (orange-0 "#ffaf87") (orange-00 "#ffd787") (orange-000 "#ffd7af")

    (linum-dark "#87875f") (linum-light "#d7d7af"))
  "The palette of colors in use with my 'chayote' theme.")

(defmacro with-palette (&rest form)
  "Evaluate `FORM' in a lexical environment with access to the
individual colors making up the theme's palette."
  `(let ((class '((class color) (min-colors 89)))
         ,@palette)
     ,@form))
#+END_SRC

To help me in modifying the theme, I've defined a function similar to
=list-colors-display=, but for showing the colors in the palette I've defined.

#+BEGIN_SRC elisp
(defun display-palette ()
  "Display names of colors defined in `PALETTE', and show what
they look like."
  (interactive)
  (with-help-window "*Chayote Colors*"
    (with-current-buffer standard-output
      (erase-buffer)
      (dolist (color palette)
        (let* ((name (symbol-name (first color)))
               (value (second color)))
          (put-text-property 0 (length name)
                             'font-lock-face `(:foreground ,value)
                             name)
          (insert name)
          (insert (propertize " " 'display '(space :align-to (- right 9))))
        (insert " ")
          (put-text-property 0 (length value)
                             'font-lock-face `(:background ,value)
                             value)
        (insert value)
          (terpri)))
      (set-buffer-modified-p nil)
      (setq truncate-lines t))))
#+END_SRC

#+BEGIN_SRC elisp
(with-palette
  (custom-theme-set-faces
   'chayote
   `(default ((,class (:foreground ,white-1 :background ,black-5 :family "Terminus" :height 90))))
   `(cursor ((,class (:background ,white-0))))

   `(link ((,class (:foreground ,blue-1 :underline t))))

   ;; Highlighting faces
   `(highlight ((,class (:background ,black-3))))
   `(hl-line ((,class (:background ,black-4))))
   `(highlight-symbol-face ((,class (:background ,green-5))))
   `(region ((,class (:background ,blue-4))))
   `(secondary-selection ((,class (:background ,blue-3 :foreground ,white-0))))
   `(isearch ((,class (:foreground ,white-1 :background ,orange-3))))
   `(lazy-highlight ((,class (:background ,magenta-3 :foreground ,white-1))))
   `(trailing-whitespace ((,class (:background ,red-3))))
   `(show-paren-match ((,class (:background ,blue-3 :foreground nil))))
   `(header-line ((,class (:background ,blue-3 :foreground ,white-0))))
   `(help-argument-name ((,class (:foreground ,magenta-1 :italic t))))
   `(eldoc-highlight-function-argument ((,class (:foreground ,green-01 :bold t :underline t :background ,green-5))))

   ;; Mode line & frames' faces
   `(mode-line ((,class (:box nil :background ,white-1 :foreground ,black-5))))
   `(mode-line-inactive ((,class (:background ,white-3 :foreground ,black-5))))
   `(mode-line-buffer-id ((,class (:box nil :foreground ,black-5 :background nil))))
   `(vertical-border ((,class (:foreground ,black-3 :background ,black-3))))

   ;; Escape and prompt faces
   `(minibuffer-prompt ((,class (:foreground ,blue-1))))
   `(escape-glyph ((,class (:foreground ,yellow-3))))
   `(error ((,class (:foreground ,red-0))))
   `(warning ((,class (:foreground ,orange-1))))
   `(success ((,class (:foreground ,green-1))))

   ;; Font lock faces
   `(font-lock-builtin-face ((,class (:foreground ,cyan-1))))
   `(font-lock-comment-delimiter-face ((,class (:inherit font-lock-comment-face))))
   `(font-lock-comment-face ((,class (:foreground ,orange-2))))
   `(font-lock-constant-face ((,class (:foreground ,cyan-2))))
   `(font-lock-doc-face ((,class (:inherit font-lock-string-face))))
   `(font-lock-doc-string-face ((,class (:inherit font-lock-string-face))))
   `(font-lock-function-name-face ((,class (:foreground ,blue-0))))
   `(font-lock-keyword-face ((,class (:foreground ,blue-1))))
   `(font-lock-negation-char-face ((,class (:foreground ,red-0))))
   `(font-lock-preprocessor-face ((,class (:inherit font-lock-builtin-face))))
   `(font-lock-regexp-grouping-backslash ((,class (:foreground ,yellow-1))))
   `(font-lock-regexp-grouping-construct ((,class (:foreground ,purple-1))))
   `(font-lock-string-face ((,class (:foreground ,orange-1))))
   `(font-lock-type-face ((,class (:foreground ,green-1))))
   `(font-lock-variable-name-face ((,class (:foreground ,yellow-1))))
   `(font-lock-warning-face ((,class (:weight bold :foreground ,red-2))))

   ;; org-mode
   `(org-block ((,class (:foreground ,white-1 :background ,black-4))))
   `(org-verbatim ((,class (:foreground ,blue-1 :background ,black-4))))
   `(org-link ((,class (:inherit link))))
   `(org-warning ((,class (:foreground ,white-0 :background ,red-4)))))

  (custom-theme-set-variables
   'chayote
   `(ansi-color-names-vector [,black-5 ,red-0 ,green-0 ,yellow-1
                              ,blue-1 ,purple-1 ,blue-0 ,white-1])))
#+END_SRC

** Modeline

This is the vanilla modeline without the handful of components that I consider
unimportant.

#+BEGIN_SRC elisp
(setq-default mode-line-format
              '("%e"
                mode-line-front-space
                mode-line-client
                mode-line-modified
                " "
                mode-line-directory
                mode-line-buffer-identification
                " "
                mode-line-position
                " "
                mode-line-modes
                mode-line-misc-info
                mode-line-end-spaces))
#+END_SRC

To make things a little easier on my eyes, I've chosen to add visual separation
between my additions to the modeline.

#+BEGIN_SRC elisp
(defconst mode-line-separator " | "
  "A separator to place between components of the modeline.")
#+END_SRC

A function to simplify the addition of new =:eval= forms to the end of
=mode-line-format=.

#+BEGIN_SRC elisp
(defun add-to-mode-line (widget)
  "Appends a `MODE-LINE-SEPARATOR' and `WIDGET' onto the end of
`MODE-LINE-FORMAT'."
  (let ((eval-form `(:eval (funcall ,widget))))
    (setq-default mode-line-format
                  (append mode-line-format
                          (list mode-line-separator eval-form)))))
#+END_SRC

My implementation of a clock for the modeline. The modeline is refreshed by a
timer to ensure that it doesn't go too stale, as it could theoretically go
several minutes without being updated.

#+BEGIN_SRC elisp
(add-to-mode-line
 (lambda () (format-time-string "%Y-%m-%d %H:%M")))

(let ((timer (run-at-time t 60.0 #'ignore)))
  (timer-set-function timer
                      (lambda ()
                        (force-mode-line-update))))
#+END_SRC

My implementation of a battery monitor for the modeline. Because strings in
=mode-line-format= can contain control sequences, the percent symbol has to be
escaped twice -- once for =battery-format=, and once for =mode-line-format=.

#+BEGIN_SRC elisp
(use-package battery
  :ensure t
  :config
  (add-to-mode-line
   (lambda ()
     (let* ((status (battery-linux-sysfs))
            (fullness (string-to-number (cdr (assoc 112 status))))
            (text (battery-format "%L: %t, %p%%%%" status))
            (low-battery-face '(:foreground "white"
                                :background "red")))
       (when (< fullness 10.0)
         (put-text-property 0 (length text)
                            'font-lock-face low-battery-face
                            text))
       text))))
#+END_SRC

* EXWM

Yes, I use Emacs as my window manager. You should try it out some time!

#+BEGIN_SRC elisp
(use-package exwm
  :ensure t
  :config
  (require 'exwm-config)
  (exwm-enable)
#+END_SRC

I find that four workspaces is enough to start out with, and I like being able
to use my X windows across workspaces.

#+BEGIN_SRC elisp
  :init
  (setq exwm-workspace-number 4
        exwm-workspace-show-all-buffers t
        exwm-layout-show-all-buffers t)
#+END_SRC

"Global key bindings" in EXWM work essentially anywhere, including buffers that
are currently in char mode. The bindings below should be fairly straightforward.
I've taken this as an opportunity to incorporate windmove to my workflow, now
that I have ?\s at my disposal. The choice of keys for that was inspired by the
WASD movement typical of first-person shooter games.

#+BEGIN_SRC elisp
  :init
  (setq exwm-input-global-keys
        `(([?\s-r] . exwm-reset)
          ([?\s-w] . windmove-up)
          ([?\s-a] . windmove-left)
          ([?\s-s] . windmove-down)
          ([?\s-d] . windmove-right)
          ([?\s-p] . (lambda (command)
                       (interactive (list (read-shell-command "$ ")))
                       (start-process-shell-command command nil command)))
          ([?\s-X] . (lambda ()
                       (interactive)
                       (start-process "" nil "/usr/bin/slock")))

          ;; Keys are offset such that <s-1> corresponds to the 0th workspace.
          ,@(mapcar (lambda (i)
                      `(,(kbd (format "s-%d" i)) .
                        (lambda ()
                          (interactive)
                          (exwm-workspace-switch-create ,(- i 1)))))
                    (number-sequence 1 9))))
#+END_SRC

Ah, yes. Simulation keys, the real reason I decided to install EXWM.

#+BEGIN_SRC elisp
  :init
  (setq exwm-input-simulation-keys
        '(([?\C-b] . [left])
          ([?\M-b] . [C-left])
          ([?\C-f] . [right])
          ([?\M-f] . [C-right])
          ([?\C-p] . [up])
          ([?\C-n] . [down])
          ([?\C-a] . [home])
          ([?\C-e] . [end])
          ([?\M-v] . [prior])
          ([?\C-v] . [next])
          ([?\C-d] . [delete])
          ([?\C-k] . [S-end delete])

          ([?\C-w] . [?\C-x])
          ([?\M-w] . [?\C-c])
          ([?\C-y] . [?\C-v])

          ([?\C-s] . [?\C-f])))
#+END_SRC

EXWM's buffers are named =*EXWM*= upon creation, which makes switching between
windows a pain. This snippet renames buffers when their class or title changes.

#+BEGIN_SRC elisp
  :hook
  (exwm-update-class . (lambda ()
                         (exwm-workspace-rename-buffer exwm-class-name)))
  (exwm-update-title . (lambda ()
                         (when (not exwm-instance-name)
                           (exwm-workspace-rename-buffer exwm-title)))))
#+END_SRC

Start the Emacs daemon so that =emacsclient= can be used from the command line
to pop a new buffer for editing.

#+BEGIN_SRC elisp
(server-start)
#+END_SRC

EXWM has issues popping any sort of pinentry window, so we'll just let Emacs do
pinentry's job.

#+BEGIN_SRC elisp
(use-package epa
  :config
  (setq epa-pinentry-mode 'loopback))
#+END_SRC

* ido

Originally, I was going to try out ivy and see if it was any snappier than ido,
but it turns out that a properly-configured vanilla ido is faster than I'm used
to. It also plays nicely with EXWM/ERC.

#+BEGIN_SRC elisp
(use-package ido
  :ensure t
  :config
  (ido-mode 1)
#+END_SRC

Fix =ido-buffer-window-other-frame= to play nicely with EXWM.

#+BEGIN_SRC elisp
  (exwm-config-ido)
#+END_SRC

Cap the number of candidates to make it even snappier, and for the same reason,
don't use the annoying built-in ffap functionality.

#+BEGIN_SRC elisp
  :init
  (setq ido-max-prospects 10)
  (setq ido-use-filename-at-point nil)
#+END_SRC

This is a preference of hygene. Stores the ido state in the same directory as
auto-save state and Emacs's backup files.

#+BEGIN_SRC elisp
  (setq ido-save-directory-list-file "~/.cache/emacs/ido.last"))
#+END_SRC

* Org

Some general hygene -- place generated images in the same directory as backup
files.

#+BEGIN_SRC elisp
(use-package org
  :init
  (setq org-latex-preview-ltxpng-directory "~/.cache/emacs/ltximg/")
  (setq org-preview-latex-image-directory "~/.cache/emacs/ltximg/")
#+END_SRC

Only load the =org-contrib= modules that I actually use.

#+BEGIN_SRC elisp
  (setq org-modules '(org-drill))
#+END_SRC

Some general configurations for quality-of-life and appearance.

#+BEGIN_SRC elisp
  (setq org-return-follows-link 't)
  (setq org-startup-folded 'nil)
  (setq org-tags-column 100)
#+END_SRC

Don't indent text following a headline.

#+BEGIN_SRC elisp
  (setq org-adapt-indentation nil)
#+END_SRC

Fix =org-src= blocks such that <tab> indents according to the mode's indentation
rules, and so that there is no implicit indentation of the source code ([[https://stackoverflow.com/questions/15773354/indent-code-in-org-babel-src-blocks][1]], [[https://emacs.stackexchange.com/questions/9472/org-mode-source-block-doesnt-respect-parent-buffer-indentation][2]]).

#+BEGIN_SRC elisp
(setq org-src-tab-acts-natively t)
(setq org-edit-src-content-indentation 0)
#+END_SRC

Scale up embedded LaTeX so that I can actually read it.

#+BEGIN_SRC elisp
 (setq org-format-latex-options
       (plist-put org-format-latex-options :scale 1.5))
#+END_SRC

** Workflow

Automatically open a buffer named =*Mind Dump*= to, well, save all of my
thoughts. They're dated and saved in a directory so I can =ag= them. This is the
closest thing I will ever have to an =ag= inside my brain.

#+BEGIN_SRC elisp
(defvar mind-dump-directory "~/Notes/Mind Dumps"
  "Where to store dated 'mind dump' files.")

(let* ((filename (concatenate 'string
                              (file-name-as-directory mind-dump-directory)
                              (format-time-string "%Y-%m-%d")
                              ".org"))
       (buffer (find-file-noselect filename)))
  (set-buffer buffer)
  (rename-buffer "*Mind Dump*"))
#+END_SRC

** Agenda

Rather convoluted agenda setup to show me:
- The tasks I've marked as needing to be done today.
- The inbox items I need to process.
- My daily habits (implemented as recurring Org TODO's).
- A view of deadlines and scheduled items for the week ahead.

#+BEGIN_SRC elisp
(setq org-agenda-files '("~/Notes/GTD/Habits.org"
                         "~/Notes/GTD/Inbox.org"
                         "~/Notes/GTD/Actionable.org"))

(let ((entry-done
       '(lambda () (org-agenda-skip-entry-if 'todo 'done)))

      (subtree-is-habit
       '(lambda ()
          (let ((subtree-end (save-excursion (org-end-of-subtree t))))
            (if (string= (org-entry-get nil "STYLE") "habit")
                subtree-end
              nil))))

      (subtree-is-not-habit
       '(lambda ()
          (let ((subtree-end (save-excursion (org-end-of-subtree t))))
            (if (not (string= (org-entry-get nil "STYLE") "habit"))
                subtree-end
              nil))))

      (subtree-is-not-inbox
       '(lambda ()
          (let ((subtree-end (save-excursion (org-end-of-subtree t))))
            (if (not (search "Inbox.org" (buffer-name)))
                subtree-end
              nil)))))

  (setq org-agenda-custom-commands
        `(("d" "Daily"
           ((tags "PRIORITY=\"A\""
                  ((org-agenda-skip-function ,entry-done)
                   (org-agenda-overriding-header "Tasks for Today:")))
            (alltodo ""
                     ((org-agenda-skip-function ,subtree-is-not-inbox)
                      (org-agenda-overriding-header "Inbox:")))
            (agenda ""
                    ((org-agenda-span 'day)
                     (org-agenda-skip-function ,subtree-is-not-habit)
                     (org-deadline-warning-days 0)
                     (org-agenda-overriding-header "Habits:")))
            (agenda ""
                    ((org-agenda-span 'week)
                     (org-agenda-skip-function ,subtree-is-habit)
                     (org-agenda-overriding-header "Week Ahead:"))))
           ((org-agenda-compact-blocks t))))))
#+END_SRC

** Drill

Scan the directory of the current buffer's file for other items -- this is so
that I can spread my cards across multiple files and still be tested on all of
them when I run =org-drill=.

#+BEGIN_SRC elisp
(setq org-drill-scope 'directory)
#+END_SRC

Shut up the nagging "are you studying enough!?" message if I don't get enough
items right on the first try. It's unhelpful and really just annoying.

#+BEGIN_SRC elisp
(setq org-drill-forgetting-index 100)
#+END_SRC

* Dired

Hide the targets of symbolic links in dired listings. This is just a visual
preference of mine.

#+BEGIN_SRC elisp
(use-package dired
  :ensure nil
  :init
  (setq-default dired-listing-switches "-alL"))
#+END_SRC

* TODO Gnus

#+BEGIN_SRC elisp
(setq gnus-init-file "~/.emacs.d/gnus"
      gnus-startup-file "~/.newsrc"
      gnus-directory "~/.local/share/gnus/News/"
      gnus-article-save-directory "~/.local/share/gnus/News/"
      gnus-kill-files-directory "~/.local/share/gnus/News/"
      gnus-uu-default-dir "~/.local/share/gnus/News/"
      gnus-agent-directory "~/.local/share/gnus/News/agent/"
      gnus-x-face-directory "~/.local/share/gnus/News/x-faces"
      nndiary-directory "~/.local/share/gnus/News/diary/"
      nndraft-directory "~/.local/share/gnus/News/drafts/"
      gnus-duplicate-file "~/.local/share/gnus/News/suppression"
      gnus-cache-active-file "~/.local/share/gnus/News/cache/active"
      gnus-cache-directory "~/.local/share/gnus/News/cache/"
      nnfolder-newsgroups-file "~/.local/share/gnus/Mail/newsgroups"
      gnus-home-directory "~/.local/share/gnus"
      mail-source-directory "~/.local/share/gnus/Mail/"
      message-directory "~/.local/share/gnus/Mail/"
      smime-certificate-directory "~/.local/share/gnus/Mail/certs/"
      smtpmail-queue-dir "~/.local/share/gnus/Mail/queued-mail/"
      nsm-settings-file "~/.cache/emacs/network-security.data")

(setq gnus-thread-sort-functions 'gnus-thread-sort-by-most-recent-number)
#+END_SRC

* Elfeed

I don't like =.elfeed= in my home directory, so I'll give it the [[Gnus]] treatment.

#+BEGIN_SRC elisp
(setq elfeed-db-directory "~/.local/share/elfeed")
#+END_SRC

All of the feeds I'm subscribed to. A reduced fat version of this list is
available [[http://jakob.space/links/][on my website]] with links to the sites instead of RSS feed URLs.

#+BEGIN_SRC elisp
(setq elfeed-feeds
      '(("https://www.phoronix.com/rss.php" news)
        ("https://paleotronic.com/feed/" news)
        ("https://lobste.rs/newest.rss" news)
        ("https://tilde.news/newest.rss" news)
        ("https://this-week-in-rust.org/atom.xml" news)
        ("https://readrust.net/all/feed.rss" news)
        ("http://planet.lisp.org/rss20.xml" news)

        ("https://xkcd.com/rss.xml" webcomic)
        ("https://www.foxtrot.com/feed/" webcomic)
        ("http://pbfcomics.com/feed/" webcomic)
        ("http://www.smbc-comics.com/comic/rss" webcomic)
        ("http://interglacial.com/rss/bob_the_angry_flower.rss" webcomic)

        ("https://eev.ee/feeds/blog.atom.xml" blog)
        ("http://fabiensanglard.net/rss.xml" blog)
        ("https://drewdevault.com/feed.xml" blog)
        ("http://feeds.feedburner.com/GynvaelColdwindEN?format=xml" blog)
        ("http://nullprogram.com/feed/" blog)
        ("https://aixxe.net/rss" blog)
        ("https://blog.soykaf.com/post/index.xml" blog)
        ("https://bernsteinbear.com/feed" blog)
        ("https://www.nayuki.io/rss20.xml" blog)
        ("https://travisgoodspeed.blogspot.com/feeds/posts/default" blog)
        ("http://emacshorrors.com/feed.atom" blog)
        ("http://dsasmblr.com/feed/" blog)
        ("https://0x90r00t.com/feed/" blog)
        ("https://outflux.net/blog/feed/" blog)
        ("https://blog.krnl386.com/index.php?feed/atom" blog)
        ("http://shell-storm.org/rss.xml" blog)
        ("http://sh3llc0d3r.com/feed/" blog)
        ("https://www.soldierx.com/rss.xml" blog)
        ("http://technomancy.us/feed/atom.xml" blog)
        ("https://rufflewind.com/feed.xml" blog)
        ("http://j00ru.vexillium.org/?feed=rss2" blog)
        ("https://dev.krzaq.cc/feed/" blog)
        ("http://asawicki.info/news_rss.php5" blog)
        ("https://www.filfre.net/feed/" blog)
        ("http://radare.today/index.xml" blog)
        ("https://lukesmith.xyz/rss.xml" blog)
        ("https://nickcano.com/rss/" blog)
        ("https://infinityplusonemath.wordpress.com/feed/" blog)
        ("https://www.rtl-sdr.com/feed/" blog)
        ("https://retro.moe/feed/" blog)
        ("https://objective-see.com/rss.xml" blog)
        ("http://meh.schizofreni.co/rss" blog)
        ("http://feeds.feedburner.com/michaelnielsen/wmna" blog)
        ("https://wargio.github.io/feed.xml" blog)
        ("http://emacsninja.com/feed.atom" blog)
        ("https://blog.baturin.org/feeds/atom.xml" blog)
        ("https://bluishcoder.co.nz/rss.xml" blog)
        ("https://leotindall.com/index.xml" blog)
        ("https://blog.separateconcerns.com/feed.atom" blog)
        ("https://deftly.net/rss.xml" blog)
        ("https://eligrey.com/feed/" blog)
        ("https://nerderati.com/" blog)
        ("https://zayenz.se/index.xml" blog)
        ("http://charliethe.ninja/feed.xml" blog)
        ("http://www.charlesetc.com/index.xml" blog)
        ("https://ramsdenj.com/feed.xml" blog)
        ("https://nick.zoic.org/feed.rss" blog)
        ("https://gpfault.net/rss.xml" blog)
        ("https://blog.demofox.org/feed/" blog)
        ("https://floooh.github.io/feed.xml" blog)
        ("https://erkaman.github.io/rss.xml" blog)
        ("http://samskivert.com/blog/index.xml" blog)
        ("https://marioslab.io/posts/rss.xml" blog)
        ("https://blog.burntsushi.net/index.xml" blog)
        ("https://frederik-braun.com/feeds/all.rss.xml" blog)
        ("http://www.wezm.net/feed/" blog)
        ("https://theta.eu.org/feed.xml" blog)
        ("https://lemire.me/blog/feed/" blog)
        ("https://arp242.net/feed.xml" blog)
        ("https://jamchamb.github.io/feed.xml" blog)
        ("https://muto.ca/feed.xml" blog)
        ("https://rocx.rocks/rss.xml" blog)
        ("https://norasandler.com/feed.xml" blog)
        ("http://faehnri.ch/feed.xml" blog)
        ("https://pwnaccelerator.github.io/feed.xml" blog)
        ("https://www.cambus.net/atom.xml" blog)
        ("https://twobithistory.org/feed.xml" blog)
        ("https://darksi.de/rss.xml" blog)
        ("https://hackaday.com/blog/feed/" blog)
        ("http://rkallos.com/feeds/all.rss.xml" blog)
        ("https://pharr.org/matt/blog/feed.xml" blog)
        ("https://chriszheng.science/atom.xml" blog)
        ("http://bitcannon.net/index.xml" blog)
        ("https://vfoley.xyz/rss.xml" blog)
        ("https://blog.kingcons.io/rss.xml" blog)
        ("http://blog.macrolet.net/rss.xml" blog)
        ("http://www.stylewarning.com/blog/rss.xml" blog)
        ("http://feeds.feedburner.com/stevelosh?format=xml" blog)
        ("https://phoenhex.re/feed.xml" blog)
        ("http://lambda-the-ultimate.org/rss.xml" blog)
        ("https://rakhim.org/index.xml" blog)
        ("http://www.evanmiller.org/news.xml" blog)
        ("http://lispblog.xach.com/rss" blog)
        ("https://medium.com/feed/@alexgolec" blog)
        ("https://wbenny.github.io/feed.xml" blog)
        ("http://vihart.com/feed/" blog)
        ("https://cryogenix.net/rss.xml" blog)
        ("http://www.codersnotes.com/notes/feed" blog)
        ("https://ambrevar.xyz/rss.xml" blog)
        ("https://hardmath123.github.io/feed.xml" blog)
        ("https://wingolog.org/feed/atom" blog)
        ("https://blog.0day.rocks/feed" blog)
        ("https://tymoon.eu/api/reader/atom" blog)
        ("https://wolf480pl.github.io/feed.xml" blog)
        ("https://yingtongli.me/blog/feed.xml" blog)
        ("https://text.causal.agency/feed.atom" blog)
        ("https://programmingisterrible.com/rss" blog)
        ("https://dehora.net/journal?format=RSS" blog)))
#+END_SRC

* Pretty Symbols

Enable =prettify-symbols= globally.

#+BEGIN_SRC elisp
(use-package pretty-symbols
  :ensure nil
  :config
  (global-prettify-symbols-mode t))
#+END_SRC

This is snippet was taken verbatim from [[https://emacs.stackexchange.com/questions/17283/is-it-possible-to-get-prettified-symbols-in-org-mode-source-blocks][Emacs StackExchange]] to enable
=prettify-symbols= in Org source code blocks. Sadly, I can't think of a way to
implement this as advice.

#+BEGIN_SRC elisp
;; TODO: Can this be implemented as Elisp advice?
(defun org-src-font-lock-fontify-block (lang start end)
  "Fontify code block.
This function is called by emacs automatic fontification, as long
as `org-src-fontify-natively' is non-nil."
  (let ((lang-mode (org-src--get-lang-mode lang)))
    (when (fboundp lang-mode)
      (let ((string (buffer-substring-no-properties start end))
        (modified (buffer-modified-p))
        (org-buffer (current-buffer)) pos next)
    (remove-text-properties start end '(face nil))
    (with-current-buffer
        (get-buffer-create
         (concat " org-src-fontification:" (symbol-name lang-mode)))
      (delete-region (point-min) (point-max))
      (insert string " ") ;; so there's a final property change
      (unless (eq major-mode lang-mode) (funcall lang-mode))
      ;; Avoid `font-lock-ensure', which does not display fonts in
      ;; source block.
      (font-lock-fontify-buffer)
      (setq pos (point-min))
      (while (setq next (next-single-property-change pos 'face))
        (put-text-property
         (+ start (1- pos)) (1- (+ start next)) 'face
         (get-text-property pos 'face) org-buffer)
        (setq pos next))
      ;; Addition: also copy 'composition info for prettified symbols
      (setq pos (point-min))
      (while (setq next (next-single-property-change pos 'composition))
        (put-text-property
         (+ start (1- pos)) (1- (+ start next)) 'composition
         (get-text-property pos 'composition) org-buffer)
        (setq pos next))
      ;; End addition
      )
    (add-text-properties
     start end
     '(font-lock-fontified t fontified t font-lock-multiline t))
    (set-buffer-modified-p modified)))))
#+END_SRC

* Savehist

I don't really care about persisting minibuffer history between sessions.

#+BEGIN_SRC elisp
(use-package savehist
  :ensure nil
  :config
  (savehist-mode -1))
#+END_SRC

© 2015 - 2026 Jakob L. Kreuze