-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
2924 lines (2626 loc) · 111 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; no-byte-compile: t -*-
;;;* Introduction
;;; This file bootstraps the configuration, which is divided into a number of
;;; other files.
;;; Byte compilation is disabled for this file to avoid ever loading stale
;;; bytecode. The commands in this file will ensure that stale bytecode is
;;; never loaded for other files.
(defmacro c-setq (variable value &optional comment)
"Exactly like setq, but handles custom.
If VARIABLE was declared by `defcustom', then use `customize-set-variable' to
set it. Otherwise, use just `set-default'. Taken from http://lists.gnu.org/archive/html/emacs-devel/2017-11/msg00119.html."
`(if (get ',variable 'custom-type)
(customize-set-variable ',variable ,value ,comment)
(set-default ',variable ,value)))
(setq debug-on-error t)
(add-to-list 'debug-ignored-errors 'search-failed)
;;;* Storage for variables configured via the interactive 'customize' interface
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file t)
;;;* gc-cons-threshold
;;; Set this higher in the minibuffer, but don't make it too bad other wise
;;; you'll figure out quick
(c-setq gc-cons-threshold (* 16 1024 1024) "\
Set gc-cons-threshold to a higher value. This should be done before
searching for packages because package searches and installation tend to
generate a lot of garbage. Cite:
http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/.")
(defun my-minibuffer-setup-hook ()
"Disable GC inside minibuffer.
See also `my-minibuffer-exit-hook'."
(setq gc-cons-threshold most-positive-fixnum))
(defun my-minibuffer-exit-hook ()
"Re-enable GC upon exiting minibuffer.
See also `my-minibuffer-setup-hook'."
(setq gc-cons-threshold (* 16 1024 1024)))
(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook)
;;;* Package loading
;;; Avoid loading .elc files older than their corresponding .el file.
(c-setq load-prefer-newer t)
;;; Fix TLS certificate "could not be verified" errors
;;; (http://emacs.stackexchange.com/a/18070).)
(c-setq gnutls-verify-error t)
(c-setq tls-checktrust 'ask)
(c-setq straight-repository-branch "develop")
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package) ; Enable :straight in ‘use-package’
(use-package bind-key :straight t) ; To make :bind work
(use-package diminish :straight t) ; To use :diminish
(use-package benchmark-init
:straight t
;; To disable collection of benchmark data after init is done.
:hook (after-init . benchmark-init/deactivate))
(use-package call-log
:straight (:host github :repo "jordonbiondo/call-log"
:fork (:host nil :repo "[email protected]:telotortium/call-log")))
;;; Use auto-compile to recompile bytecode whenever files are loaded or saved.
(use-package auto-compile
:straight t
:config
(auto-compile-on-load-mode)
(auto-compile-on-save-mode))
;;;* Basic startup configuration
;;; Disable startup screen
(c-setq inhibit-startup-message t)
;;; Command to restart emacs from within emacs
(use-package restart-emacs :straight t)
;;; Allow access from emacsclient
(use-package server
:straight (:type built-in)
:config
(c-setq server-name "server")
(c-setq server-socket-dir "~/.emacs.d/server")
(c-setq server-use-tcp t)
(defun warn-server-name-changed (original-server-name)
(when (not (string= server-name original-server-name))
(warn "server-name = \"%s\", should be \"%s\""
server-name original-server-name)))
(run-at-time nil 30 #'warn-server-name-changed server-name)
(unless (eq (server-running-p) t) (server-start)))
;;;* Leuven theme
(use-package leuven-theme
:straight t
:custom
(leuven-scale-outline-headlines nil)
:config
(load-theme 'leuven t)
(load-theme 'leuven-customization t))
;;;* Ivy configuration
(use-package amx :straight t)
(use-package counsel
:diminish ivy-mode
:diminish counsel-mode
:straight t
:custom
(ivy-use-virtual-buffers t)
(ivy-count-format "%d/%d ")
(enable-recursive-minibuffers t)
(ivy-initial-inputs-alist '((Man-completion-table . "^")
(woman . "^")))
:config
(ivy-mode 1)
(counsel-mode 1)
(global-set-key "\C-s" 'swiper)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c j") 'counsel-git-grep)
(global-set-key (kbd "C-c k") 'counsel-rg)
(global-set-key (kbd "C-x l") 'counsel-locate)
(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
(global-set-key (kbd "C-x b") 'ivy-switch-buffer)
(defun counsel-rg-org (search-archives)
"Specialize ‘counsel-rg’ for Org-mode files.
Unless ‘\\[universal-argument]’ prefix ARG is used, don’t include archives in
the search. Saves all Org buffers beforehand so that ‘counsel-rg’ sees the
contents of all Org-mode buffers."
(interactive "P")
(org-save-all-org-buffers)
(let* ((extra-rg-args (concat "--smart-case"
" --type-add 'org:*.org'"
" --type-add 'org:*.org_archive'"
" --type org")))
(when (not search-archives)
(setq extra-rg-args (concat extra-rg-args " '-g!*.org_archive'")))
(counsel-rg nil "~/Documents/org/" extra-rg-args nil)))
(global-set-key (kbd "C-c q") #'counsel-rg-org)
;; Unbind ivy-restrict-to-matches - always annoys me during org-capture.
(define-key ivy-minibuffer-map (kbd "S-SPC") nil)
(define-key read-expression-map (kbd "C-r") 'counsel-expression-history))
;;;* Evil configuration
;; Dependency of evil-mode
(use-package undo-tree
:straight t
:diminish undo-tree-mode)
(use-package evil
:straight t
:init
(c-setq evil-want-keybinding nil)
:config (evil-mode 1))
;; Space as leader
(use-package evil-leader
:straight t
:config
(global-evil-leader-mode)
(evil-leader/set-leader "<SPC>"))
;; Scroll with C-u and access universal-argument with <Leader>-u.
(c-setq evil-want-C-u-scroll t)
(evil-leader/set-key "u" 'universal-argument)
(evil-leader/set-key "s" (lambda () (interactive) (switch-to-buffer "*scratch*")))
;; Evil magic search
(c-setq evil-magic 'very-magic)
(c-setq evil-search-module 'evil-search)
(use-package evil-collection
:straight t
:init (evil-collection-init)
:config
;; Avoid conflict with evil-org
(setq evil-collection-outline-bind-tab-p nil))
(defun switch-to-previous-buffer ()
"Switch to previously current buffer."
(interactive)
(switch-to-buffer (other-buffer (current-buffer))))
;; Disable all the C-<number> keys, and give C-^ and C-6 the same behavior as
;; they have in Vim.
(define-key evil-normal-state-map (kbd "C-^") 'switch-to-previous-buffer)
(define-key evil-normal-state-map (kbd "C-6") 'switch-to-previous-buffer)
(dolist (key (mapcar 'kbd
'("C-1" "C-2" "C-3" "C-4" "C-5"
"C-7" "C-8" "C-9" "C-0")))
(define-key evil-normal-state-map key (lambda () (interactive))))
;; Make C-w C-{h,j,k,l} equivalent to C-w {h,j,k,l}
(define-key evil-window-map "\C-h" 'evil-window-left)
(define-key evil-window-map "\C-j" 'evil-window-down)
(define-key evil-window-map "\C-k" 'evil-window-up)
(define-key evil-window-map "\C-l" 'evil-window-right)
;; Kill current buffer but keep its frame around
(define-key evil-normal-state-map "Q" 'kill-this-buffer)
(use-package evil-commentary
:straight t
:config
(evil-commentary-mode))
(evil-leader/set-key
";" 'evil-ex
":" 'evil-ex)
;; Shortcut to M-x
(evil-ex-define-cmd "mx" #'counsel-M-x)
(define-key evil-ex-map "mx" #'counsel-M-x)
(evil-leader/set-key "SPC" 'counsel-M-x)
;; change mode-line color by evil state
(let ((default-color (cons (face-background 'mode-line)
(face-foreground 'mode-line))))
(add-hook 'post-command-hook
(lambda ()
(let ((color (cond ((minibufferp) default-color)
((evil-insert-state-p) '("#e80000" . "#ffffff"))
((and (evil-emacs-state-p)
(buffer-modified-p))
'("#44b3f8" . "#ffffff"))
((evil-emacs-state-p) '("#444488" . "#ffffff"))
((buffer-modified-p) '("#006fa0" . "#ffffff"))
(t default-color))))
(set-face-background 'mode-line (car color))
(set-face-foreground 'mode-line (cdr color))))))
(use-package evil-surround
:straight t
:config
(global-evil-surround-mode 1))
(use-package evil-visualstar
:straight t
:config
(global-evil-visualstar-mode))
(use-package evil-numbers
:straight t
:bind (:map evil-normal-state-map
("C-c =" . evil-numbers/inc-at-pt)
("C-c +" . evil-numbers/inc-at-pt)
("C-c -" . evil-numbers/dec-at-pt)
("C-c _" . evil-numbers/dec-at-pt)))
;;;* Miscellaneous
;; Make default encoding UTF-8 everywhere
(c-setq current-language-environment "UTF-8")
(prefer-coding-system 'utf-8)
;; Convenience bindings for isearch buffer
(define-key isearch-mode-map (kbd "<up>") 'isearch-ring-retreat)
(define-key isearch-mode-map (kbd "<down>") 'isearch-ring-advance)
;; Auto-indent
(use-package clean-aindent-mode
:straight t
:bind (:map global-map ("RET" . #'newline-and-indent))
:config (clean-aindent-mode 1))
;; No tabs
(setq-default indent-tabs-mode nil)
;; Automatically wrap long lines
(setq-default fill-column 79)
(defun prog-mode-wrap-hook ()
"Set auto-fill for comments only in `prog-mode'."
(setq-local comment-auto-fill-only-comments t)
(auto-fill-mode t)
(diminish 'auto-fill-function))
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'prog-mode-hook 'prog-mode-wrap-hook)
;;; Disable scrollbars
(scroll-bar-mode -1)
;;; Line and column numbers
(c-setq display-line-numbers-type 'visual)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
(add-hook 'text-mode-hook #'display-line-numbers-mode)
(line-number-mode 1)
(column-number-mode 1)
(use-package rg
:straight t
:commands (rg rg-project rg-dwim)
:config
(c-setq rg-custom-type-aliases
'(("org" . "*.org *.org_archive")))
(rg-define-search rg-org
"Run rg on my Org files"
:query ask
:files "org"
:dir "~/Documents/org"
:confirm prefix
:flags ("--smart-case") ; Emacs default search is smart case
:menu ("Custom" "o" "Org-mode files"))
(defun rg-org-save-files (&rest unused)
"Run ‘org-save-all-org-buffers’ so ‘rg-org’ searches all file contents."
(org-save-all-org-buffers))
(advice-add 'rg-org :before #'rg-org-save-files))
;;; Company
(use-package company-flx
:straight t
:config
(with-eval-after-load 'company
(company-flx-mode +1)))
(use-package company
:straight t
:diminish company-mode
;; Force company to load eagerly, which loads the version from straight in
;; preference to any system-installed versions.
:demand t
:bind
(:map company-active-map
("RET" . company-complete-selection))
:custom
(company-tooltip-limit 20 "bigger popup window")
(company-idle-delay .3 "decrease delay before autocompletion popup shows")
(company-echo-delay 0 "remove annoying blinking")
:hook (after-init . global-company-mode))
(use-package company-go :straight t)
;;; Flycheck
(use-package flycheck
:straight t ; May want to use built-in version at Google
:defer t ; init-local-google will locate this
:hook (after-init . global-flycheck-mode)
:custom
;; Inherit Emacs load-path from current session - prevents annoying errors
;; from custom packages.
(flycheck-emacs-lisp-load-path 'inherit)
;; Don't re-run Flycheck syntax checkers on inserting new lines, to save
;; performance.
(flycheck-check-syntax-automatically '(save idle-change mode-enabled))
(flycheck-idle-change-delay 4))
;;; syntax highlighting for vimscript files
(use-package vimrc-mode
:straight t
:mode ".vim\\(rc\\)?$")
;;; Markdown
(use-package markdown-mode
:straight t
:commands (markdown-mode gfm-mode)
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init (c-setq markdown-command
"pandoc -f markdown -t html --toc -s --mathjax")
:config
;; Make `<tab>` only call `indent-relative` in Evil insert mode, not cycle.
(add-hook 'markdown-mode-hook
(lambda ()
(define-key markdown-mode-map (kbd "<tab>")
(lambda (&rest args)
(interactive "P")
(cond ((and (featurep 'evil) (evil-insert-state-p))
(apply 'indent-relative args))
(t (apply 'markdown-cycle args))))))))
;; Give buffers editing files with the same basename more distinctive names
;; based on directory.
(use-package uniquify
:straight (:type built-in)
:custom
(uniquify-buffer-name-style 'post-forward-angle-brackets))
;; Save mini-buffer history
(use-package savehist
:straight (:type built-in)
:custom
(savehist-additional-variables
'(kill-ring search-ring regexp-search-ring compile-history))
(savehist-file
(expand-file-name (concat (file-name-as-directory "cache") "savehist")
user-emacs-directory))
(history-length 5000)
:config
(savehist-mode 1))
;; Disable tool bar
(message "turn off tool bar")
(tool-bar-mode -1)
;; Rust mode
(use-package rust-mode
:straight t
:mode "\\.rs\\'")
;; Lua mode
(use-package lua-mode
:straight t
:mode "\\.lua$"
:interpreter "lua")
;; Java
(use-package eclim
:straight t
:config
(require 'eclimd)
(global-eclim-mode))
(use-package company-emacs-eclim
:straight t
:config
(company-emacs-eclim-setup))
;; Javascript
(use-package js-mode
:straight (:type built-in)
:mode ("\\.js\\'" "\\.javascript\\'"))
;; Multi Web Mode - automatically switch to right major mode in HTML files
(use-package multi-web-mode
:straight t
:custom
(mweb--major-mode 'html-mode)
(mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
(js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
(css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
(mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
:config
(multi-web-global-mode 1))
(use-package rainbow-delimiters
:straight t
:commands rainbow-delimiters-mode
:init (add-hook 'prog-mode-hook 'rainbow-delimiters-mode))
(use-package rainbow-identifiers
:straight t
:hook (prog-mode . rainbow-identifiers-mode)
:config
:custom
(rainbow-identifiers-choose-face-function
#'rainbow-identifiers-cie-l*a*b*-choose-face)
(rainbow-identifiers-cie-l*a*b*-saturation 30)
(rainbow-identifiers-cie-l*a*b*-color-count 64)
(rainbow-identifiers-face-count 64)
;; Disable distinctive variable name face so that rainbow-identifiers-mode
;; highlights the variable at its declaration the same way as its use.
(rainbow-identifiers-faces-to-override '(font-lock-variable-name-face)))
(use-package paren
:straight (:type built-in)
:config (show-paren-mode 1))
;;; Go
(use-package go-mode
:straight t
:config
(defun my-go-mode-settings ()
(setq-local whitespace-line-column 99)
;; Use 4-space tabs since gofmt formats with tabs by default
(setq-local tab-width 4)
(setq-local tab-stop-list (number-sequence 4 200 4))
;; See https://github.com/dominikh/go-mode.el/issues/119. This regexp isn't
;; completely reliable, since it leaves comment markers in the middle of
;; the line and fails to handle other cases, but at least it comments the
;; beginning of each paragraph.
(setq-local adaptive-fill-regexp
"[ ]*\\(//+\\|\\**\\)[ ]*\\([ ]*\\([-–!|#%;>*·•‣⁃◦]+[ ]*\\)*\\)"))
(add-hook 'go-mode-hook 'my-go-mode-settings)
(defun my-go-guru-xref ()
(evil-local-set-key 'normal (kbd "C-]") #'go-guru-definition))
(add-hook 'go-mode-hook #'my-go-guru-xref 'append))
;;; Enable escaping from yasnippet snippets
(use-package yasnippet
:straight t
:diminish yas-minor-mode
:config
(yas-global-mode 1))
;;; Don't put yanks into X clipboard buffer by default
(c-setq select-enable-primary nil)
(c-setq select-enable-clipboard t)
(c-setq mouse-drag-copy-region t)
;;; Copy and paste from macOS pasteboard (from
;;; http://apple.stackexchange.com/a/127082).
(when (eq system-type 'darwin)
(defun pbcopy ()
(interactive)
(call-process-region (point) (mark) "pbcopy")
(setq deactivate-mark t))
(defun pbpaste ()
(interactive)
(call-process-region (point) (if mark-active (mark) (point)) "pbpaste" t t))
(defun pbcut ()
(interactive)
(pbcopy)
(delete-region (region-beginning) (region-end)))
(global-set-key (kbd "s-c") 'pbcopy)
(global-set-key (kbd "s-v") 'pbpaste)
(global-set-key (kbd "s-x") 'pbcut))
;;; Parinfer
(use-package paredit :straight t)
(use-package parinfer
:straight t
:bind
(("C-," . parinfer-toggle-mode))
:hook ((clojure-mode emacs-lisp-mode common-lisp-mode scheme-mode lisp-mode)
. parinfer-mode)
:init
(c-setq parinfer-extensions
'(defaults ; should be included.
pretty-parens ; different paren styles for different modes.
evil ; If you use Evil.
paredit ; Introduce some paredit commands.
smart-tab ; C-b & C-f jump positions and smart shift with tab & S-tab.
smart-yank)) ; Yank behavior depend on mode.
(c-setq parinfer-auto-switch-indent-mode t)
:config
(c-setq parinfer-lighters '(" pi:I" " pi:P")))
;;; Slime
(use-package slime
:straight t
:config
(require 'slime-autoloads)
(add-hook 'slime-repl-mode-hook #'activate-paredit-mode)
;; Stop SLIME's REPL from grabbing DEL,
;; which is annoying when backspacing over a '('
(defun override-slime-repl-bindings-with-paredit ()
(define-key slime-repl-mode-map
(read-kbd-macro paredit-backward-delete-key) nil))
(add-hook 'slime-repl-mode-hook 'override-slime-repl-bindings-with-paredit)
;; Add contrib directory to load-path for slime-fancy.
(add-to-list
'load-path
(expand-file-name
"contrib"
(file-name-directory (symbol-file #'slime-mode))))
(slime-setup '(slime-fancy slime-banner)))
;;;* Org configuration
(use-package htmlize :straight t) ; For org-publish
(straight-use-package 'org-plus-contrib)
(use-package org
:ensure nil ; Package downloaded by org-plus-contrib
:init
:config
(add-to-list 'org-modules 'org-habit)
(require 'org-agenda)
(require 'org-attach) ; Needed for attachment: links to work
(require 'org-protocol)
(require 'org-tempo))
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c b") 'org-switchb)
(global-set-key (kbd "C-c c") 'org-capture)
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "S-<f11>") #'org-clock-goto)
(global-set-key (kbd "C-<f11>") #'my-org-clock-in)
(global-set-key (kbd "C-S-<f11>") #'my-org-goto-heading)
(defun my-org-clock-in ()
"Select a recently clock-in task to clock into. See `org-clock-in'."
(interactive) (org-clock-in '(4)))
(defun my-org-goto-heading ()
"Run C-u org-refile to list all headings."
(interactive)
;; org-file doesn't work unless it's run from within an Org buffer, so find
;; an arbitrary one.
(with-current-buffer
(save-excursion
(catch 'aaa
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'org-mode)
(throw 'aaa buffer))))))
(org-refile '(4))))
(defun swiper-multi-org-agenda-files (prefix)
"Swiper-based replacement for ‘org-occur-in-agenda-files’.
With `\\[universal-argument]' prefix ARG, include archives in the search even \
if `agenda-archives' is not in `org-agenda-text-search-extra-files'."
(interactive "p")
(let* ((files (org-agenda-files))
(tnames (mapcar #'file-truename files))
(extra org-agenda-text-search-extra-files)
(search-archives (or (eq (car extra) 'agenda-archives)
(> prefix 1))))
(when search-archives
(setq extra (cdr extra))
(setq files (org-add-archive-files files)))
(dolist (f extra)
(unless (member (file-truename f) tnames)
(unless (member f files) (setq files (append files (list f))))
(setq tnames (append tnames (list (file-truename f))))))
;; First find the buffers for open agenda files.
(setq swiper-multi-buffers
(cl-remove-if #'null (mapcar #'get-file-buffer files)))
;; Set ‘swiper-multi-candidates’ as done in ‘swiper-multi-action-1’.
(setq swiper-multi-candidates
(swiper--multi-candidates
(mapcar #'get-buffer swiper-multi-buffers)))
;; Call just ‘swiper-multi-action-2’, which does the actual search text
;; completion.
(ivy-read (format "Org-files (%s) matching: " (if search-archives "with archives" "unarchived"))
swiper-multi-candidates
:action 'swiper-multi-action-2
:unwind #'swiper--cleanup
:caller 'swiper-multi)))
;;;** Org capture
;; The following code is disabled currently because it's causing Emacs capture
;; buffers to hang. Instead I'm using this configuration from Doom.
(load (expand-file-name "lisp/auto/org-capture-doom.el" user-emacs-directory))
;; ;;; Kill the frame if one was created for the capture
;; (defun my-org-capture-finalize-delete-frame-from-org-protocol (oldfun &rest args)
;; "Delete frames created by external org-protocol capture scripts.
;; This hook tests the presence of a frame parameter `org-protocol-capture' on
;; the created frame. This can be set using the `--frame-parameters' flag to
;; `emacsclient'."
;; ;; First save the current frame before the capture is finalized.
;; (let* ((frame (window-frame (get-buffer-window (current-buffer) t)))
;; ;; Ensure org-capture-refile prompt appears in foreground frame
;; (default-minibuffer-frame frame)
;; (minibuffer-auto-raise t))
;; (apply oldfun args)
;; ;; After the capture is finalized, delete the frame.
;; (when (frame-parameter frame 'org-protocol-capture)
;; ;; Use condition-case to avoid useless error if attempting to close last frame.
;; (condition-case nil
;; (delete-frame frame)
;; (error nil)))))
;; (defun my-org-capture-refile-delete-frame-from-org-protocol (oldfun &rest args)
;; "Delete frames created by external org-protocol capture scripts.
;; Advice around `org-capture-refile' to temporarily remove advice
;; `my-org-capture-delete-frame-from-org-protocol' around `org-capture-finalize'
;; while calling `org-capture-refile'. This is needed because `org-capture-refile'
;; calls `org-capture-finalize' internally. Without removing the advice, the frame
;; is closed before I have a chance to refile it.
;; Takes an UNUSED argument."
;; (unwind-protect
;; (progn
;; (advice-remove 'org-capture-finalize
;; #'my-org-capture-finalize-delete-frame-from-org-protocol)
;; (apply #'my-org-capture-finalize-delete-frame-from-org-protocol
;; oldfun args))
;; (advice-add 'org-capture-finalize
;; :around
;; #'my-org-capture-finalize-delete-frame-from-org-protocol)))
;; (defalias 'my-org-capture-kill-delete-frame-from-org-protocol
;; #'my-org-capture-refile-delete-frame-from-org-protocol)
;; (defun my-org-capture-steal-focus (&rest unused)
;; "Steal focus for frames created by external org-protocol capture scripts.
;; Stealing focus here ensures that the newly-created frame is the one from which
;; prompts are read. Otherwise, the prompt would appear on the existing frame.
;; This hook tests the presence of a frame parameter `org-protocol-capture' on the
;; newly-created frame. This can be set using the `--frame-parameters' flag to
;; `emacsclient'.
;; Takes an UNUSED argument."
;; (when (frame-parameter nil 'org-protocol-capture)
;; (x-focus-frame nil)))
;; (defun my-org-capture-buffer-sole-window ()
;; "Delete all windows containing the current Org Capture buffer except for the
;; one launched by a org-protocol Emacsclient.
;; This hook tests the presence of a frame parameter `org-protocol-capture' on
;; the newly-created frame. This can be set using the `--frame-parameters' flag to
;; `emacsclient'."
;; (run-at-time 1 nil #'my-org-capture-buffer-sole-window--inner (current-buffer)))
;; (defun my-org-capture-buffer-sole-window--inner (buf)
;; "Function scheduled from `my-org-capture-capture-buffer-sole-window' to run
;; after org-capture-mode is entered."
;; (require 'call-log)
;; (dolist (frame (frame-list))
;; (clog/msg "frame %S" frame)
;; (when (frame-parameter frame 'org-protocol-capture)
;; (clog/msg "my-org-capture-capture-buffer-sole-window: %S"
;; (get-buffer-window-list nil nil t))
;; (let* ((wnd (frame-root-window frame)))
;; (with-current-buffer buf
;; ;; Set the newly-created frame's window to the capture buffer.
;; (set-window-buffer wnd buf)
;; ;; Delete all windows except `wnd' containing the capture buffer.
;; (dolist (w (get-buffer-window-list buf nil t))
;; (clog/msg "gbwl: %S, %S : %S"
;; wnd w (eq wnd w))
;; (unless (or (eq wnd w))
;; (clog/msg "gbwl: deleting window %S" w)
;; (delete-window w)))
;; ;; Ensure newly-created frame is in the foreground.
;; (select-frame-set-input-focus frame))))))
;; (advice-add 'org-capture :before #'my-org-capture-steal-focus)
;; (add-hook 'org-capture-mode-hook #'my-org-capture-buffer-sole-window)
;; (advice-add 'org-capture-finalize
;; :around #'my-org-capture-finalize-delete-frame-from-org-protocol)
;; (advice-add 'org-capture-kill
;; :around #'my-org-capture-kill-delete-frame-from-org-protocol)
;; (advice-add 'org-capture-refile
;; :around #'my-org-capture-refile-delete-frame-from-org-protocol)
(c-setq org-agenda-files (expand-file-name "agenda_files" user-emacs-directory))
(c-setq org-agenda-span 7)
(c-setq org-agenda-start-on-weekday nil)
(c-setq org-agenda-skip-deadline-prewarning-if-scheduled t)
(defun transform-square-brackets-to-curly-ones (string-to-transform)
"Transforms [ into ( and ] into ) in STRING-TO-TRANSFORM.
Other chars left unchanged."
(concat
(mapcar #'(lambda (c)
(cond ((equal c ?\[) ?\{)
((equal c ?\]) ?\})
(t c)))
string-to-transform)))
(defun org-clock-report-buffer (&optional no-narrow)
"Evaluate all the clocktables in the buffer.
By default, evaluate only the clocktables in the current Org subtree, in order
to avoid recomputing all the clock tables in the buffer, which will take a
while in my daily-log.org file. With a prefix arg NO-NARROW, evaluate all the
clocktables in the currently visible portion of the buffer."
(interactive "P")
(save-restriction
(unless no-narrow
(org-narrow-to-subtree))
(save-excursion
(goto-char (point-min))
(while (re-search-forward "#\\\+BEGIN: clocktable" nil t)
(org-clock-report)
(forward-line 1)))))
(defcustom org-daily-log-file
(concat org-directory "/daily-log.org")
"The path to Org file in which daily log entries are captured."
:type 'file)
(c-setq org-capture-templates
`(("t" "Task" entry (file (lambda () (concat org-directory "/inbox.org")))
"
* TODO %?%^{Title}
%^{Effort}p%u
" :clock-in t :clock-resume t :jump-to-captured t)
("n" "Note" entry (file (lambda () (concat org-directory "/inbox.org")))
"
* %u %?
" :jump-to-captured t)
("i" "Idea" entry (file (lambda () (concat org-directory "/inbox.org")))
"
* %u %?REPLACE_ME :IDEA:
" :clock-in t :clock-resume t)
("j" "Journal" plain (file+weektree (lambda () (concat org-directory "/journal.org")))
"
* %U %^{Title} :journal:
:PROPERTIES:
:Effort: 9999:00
:END:
%?
" :clock-in t :clock-resume t)
("d" "Drill" entry (file+headline org-default-notes-file "Drill")
"
* Drill entry :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: hide1cloze
:Effort: 0:02
:END:
%?!|2 + 2|! equals !|4|!.
" :clock-in t :clock-resume t :jump-to-captured t)
("D" "Daily Log" entry (file+olp+datetree org-daily-log-file)
"
* %u Daily log
:PROPERTIES:
:Effort: 0:05
:END:
*Summary*:%?
*Problem*:
*Insight*:
*Tomorrow*:
#+BEGIN: clocktable :maxlevel 9 :emphasize nil :scope agenda :stepskip0 t :fileskip0 t :block %<%F> :link t
#+END: clocktable
" :time-prompt t :tree-type week :clock-in t :clock-resume t)
("W" "GTD weekly review" entry (file+olp+datetree org-daily-log-file)
"
* NEXT %u GTD weekly review
SCHEDULED: <%<%Y-%m-%d %a 13:00-14:00>>
:PROPERTIES:
:Effort: 1:00
:END:
Follow:
- [[https://gettingthingsdone.com/wp-content/uploads/2014/10/Weekly_Review_Checklist.pdf][Weekly Review Checklist]]
- \"Weekly Review\" section in Getting Things Done.
In 2015 edition: Chapter 8: \"Reflecting: Keeping It All Fresh and
Functional\", section \"The Power of the Weekly Review\".
Checklist:
- GET CLEAR
- [ ] Collect Loose Papers and Materials \\\\
Gather all accumulated business cards, receipts, and miscellaneous
paper-based materials into your in-tray.
- [ ] Get “IN” to Zero \\\\
Process completely all outstanding paper materials, journal and meeting
notes, voicemails, dictation, and emails.
- [ ] inbox.org files
- [ ] Personal email
- [ ] Personal tasks (use ~sync-tasks~)
- [ ] Corp email
- [ ] Corp tasks (use ~sync-tasks~)
- [ ] [[https://b.corp.google.com/savedsearches/5024171][Buganizer: Org-mode assigned but not captured]]
- [ ] [[https://critique.corp.google.com/#search/&q=reviewer:me+-is:submitted+-starred:me][Critique: CLs to review]]
- [ ] Close all browser tabs (use org-capture-extension to capture)
- [ ] Chats
- [ ] Empty Your Head \\\\
Put in writing and process any uncaptured new projects, action items,
waiting for’s, someday maybe’s, etc.
- GET CURRENT
- [ ] Review Action Lists \\\\
Mark off completed actions. Review for reminders of further action steps to
record.
- [ ] Review Previous Calendar Data \\\\
Review past calendar in detail for remaining action items, reference data,
etc., and transfer into the active system.
- [ ] Review Upcoming Calendar \\\\
Review upcoming calendar events–long and short term. Capture actions
triggered.
- [ ] Review Waiting For List \\\\
Record appropriate actions for any needed follow-up. Check off received
ones.
- [ ] Review Project (and Larger Outcome) Lists \\\\
Evaluate status of projects, goals, and outcomes, one by one, ensuring at
least one current action item on each. Browse through project plans,
support material, and any other work-in-progress material to trigger new
actions, completions, waiting for’s, etc.
- [ ] Review Any Relevant Checklists \\\\
Use as a trigger for any new actions.
- GET CREATIVE
- [ ] Review Someday Maybe List \\\\
Review for any projects which may now have become active, and transfer to
“Projects.” Delete items no longer of interest.
- [ ] Be Creative and Courageous \\\\
Any new, wonderful, hare-brained, creative, thought-provoking, risk-taking
ideas to add into your system???
" :time-prompt t :tree-type week :clock-in t :clock-resume t :jump-to-captured t)
("p" "Link and Text" entry (file+headline org-default-notes-file "Links")
"
* %?REPLACE_ME
Source: [[%:link][%:description]]
#+BEGIN_SRC html
<blockquote>
%i
</blockquote>
#+END_SRC
%U
")
("L" "Link" entry (file+headline org-default-notes-file "Links")
"
* %?[[%:link][%(transform-square-brackets-to-curly-ones \"%:description\")]]
%U
" :jump-to-captured t)))
;; Create ‘C-u 2 M-x org-capture’ command to refile org-capture template under
;; headline at point.
(defvar my-org-capture-rfloc nil
"Holds the RFLOC argument to pass to ‘org-refile’.")
(defun my-org-capture-under-headline (&optional goto keys)
"Capture a headline using ‘org-capture’, according to the template you \
select, and then immediately refile that headline under the headline at the \
current point. GOTO and KEYS are passed to ‘org-capture’."
(interactive "P")
(unwind-protect
(progn
(unless (eq major-mode 'org-mode)
(user-error "Must be called from an Org-mode buffer"))
;; Capture refile target at point. For format see
;; ‘org-refile-target-table’.
(setq my-org-capture-rfloc
(list
(org-display-outline-path t t nil t)
(buffer-file-name (buffer-base-buffer))
nil
(org-with-wide-buffer
(org-back-to-heading t)
(point-marker))))
(funcall #'org-capture nil keys)
(when my-org-capture-rfloc
(org-capture-goto-last-stored)
;; Refile last-captured target under the headline stored earlier.
(org-refile nil nil my-org-capture-rfloc)
;; Ensure point is at the newly-captured and refiled headline.
(org-refile-goto-last-stored)))
;; Ensure ‘my-org-capture-rfloc’ is reset.
(setq my-org-capture-rfloc nil)))
(defun my-org-capture-under-headline-prefix (_orig-fn &rest _args)
"Provide an additional “C-u 2” prefix arg to `org-capture'.
When ‘org-capture’ is called with this prefix argument, it will capture a
headline according to the template you select, and then immediately refile that
headline under the headline at the current point."
(let ((goto (nth 0 _args)))
(if (equal goto 2)
(apply #'my-org-capture-under-headline _args)
(apply _orig-fn _args))))
(advice-add 'org-capture :around #'my-org-capture-under-headline-prefix)
(defun org-today-overridden ()
(if (null org-overriding-default-time)
(org-today)
(let* ((ot
(decode-time org-overriding-default-time))
(cgreg (list (nth 4 ot) (nth 3 ot) (nth 5 ot))))
(calendar-absolute-from-gregorian cgreg))))
(defun my-org-daily-log--find-daily-log ()
(re-search-forward
(rx-to-string
`(and
line-start
(repeat 4 "*")
" "
(0+ not-newline)
,(let ((d (calendar-gregorian-from-absolute (org-today-overridden))))
(format "[%04d-%02d-%02d "
(calendar-extract-year d)
(calendar-extract-month d)
(calendar-extract-day d)))
(0+ not-newline)
"] Daily log"))))
(defun my-org-daily-log--find-today ()
(re-search-forward
(rx-to-string
`(and
line-start
(repeat 3 "*")
,(let ((d (calendar-gregorian-from-absolute (org-today-overridden))))