This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.el
2758 lines (2590 loc) · 105 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 initialization -*- lexical-binding: t; -*-
;;; Commentary:
;; This is my personal Emacs config. It works for me, but probably won't
;; for you. The general idea is to load a few things early that need to be
;; set early, like the package manager, and then use `use-package' to
;; load/defer/config everything else alphabetically.
;;; Code:
(when (< emacs-major-version 26) ; Minimum version
(error "Your Emacs is too old -- this config requires version 26 or higher"))
;; Temporarily raise the gc threshold
(setq gc-cons-threshold (* 50 1000 1000))
;;; Early birds
(progn ; startup & C source code vars
(setq user-init-file (or load-file-name buffer-file-name)
user-emacs-directory (file-name-directory user-init-file))
(message "Loading %s..." user-init-file)
;; (package-initialize)
(setq inhibit-startup-buffer-menu t
inhibit-startup-screen t
package-enable-at-startup nil
load-prefer-newer t
;; don't use popup boxes, just make the minibuffer ask
use-dialog-box nil
initial-major-mode #'org-mode
initial-scratch-message "# Unsaved notes\n\n"
;; Delete my files by moving them to the trash. I'm human and
;; occasionally delete things that I actually want later:
delete-by-moving-to-trash t
;; Emacs has some awful scrolling by default. This gets rid of that.
scroll-step 1 ; keyboard scroll one line at a time
scroll-preserve-screen-position 'always
scroll-conservatively 101
next-screen-context-lines 5
;; remove auditory clutter:
ring-bell-function #'ignore)
(advice-add #'display-startup-echo-area-message :override #'ignore)
;; Don't ever use tabs. Always use spaces.
(setq-default indent-tabs-mode nil)
;; for the lazy:
(defalias 'yes-or-no-p 'y-or-n-p)
;; remove visual clutter:
(scroll-bar-mode 0)
(tool-bar-mode 0)
(menu-bar-mode 0)
;; Emacs thinks that some new users may find some commands confusing, so
;; they're disabled by default. I use these every now and then, so let's
;; enable them by default:
(put #'downcase-region 'disabled nil)
(put #'upcase-region 'disabled nil)
(put #'narrow-to-region 'disabled nil)
;; Prefer utf8
(prefer-coding-system 'utf-8))
(progn ; `borg'
(add-to-list 'load-path (expand-file-name "lib/borg" user-emacs-directory))
(require 'borg)
(borg-initialize))
(progn ; `use-package'
(setq use-package-enable-imenu-support t)
(require 'use-package)
(setq use-package-compute-statistics t)
;; Setup a personal keymap. I'll bind various things to this later on:
(bind-keys :prefix "<f1>"
:prefix-map my/map))
(use-package auto-compile
:demand t
:custom
(auto-compile-mode-line-counter t "Show compile info in the mode-line")
(auto-compile-source-recreate-deletes-dest t)
(auto-compile-toggle-deletes-nonlib-dest t)
(auto-compile-update-autoloads t)
(auto-compile-display-buffer nil "Don't display compile buffer")
:hook
(auto-compile-inhibit-compile . auto-compile-inhibit-compile-detached-git-head)
:config
(auto-compile-on-load-mode)
(auto-compile-on-save-mode))
;; Finally, I set up no-littering, which keeps my .emacs.d folder clean by
;; putting files into appropriate subfolders rather than letting them get
;; saved all over the place:
(use-package no-littering
:demand t)
;;; end of early birds, alphabetical from here on out:
(use-package abbrev
:defer 2
:custom
(save-abbrevs 'silently)
:hook
(text-mode . abbrev-mode))
(use-package aggressive-indent
;; Keep code indented automatically
:defer 10
:config
(global-aggressive-indent-mode))
(use-package alert
;; Set it up so Emacs can send system notifications:
:defer t
:custom
(alert-default-style 'libnotify)
:config
(defun my/pause-notifications ()
"Pause notification display."
(interactive)
(shell-command "killall -SIGUSR1 dunst" nil nil)
(message "Notifications paused."))
(defun my/resume-notifications ()
"Resume notification display."
(interactive)
(shell-command "killall -SIGUSR2 dunst" nil nil)
(message "Notifications resumed.")))
(use-package anaconda-mode
;; sets up some nice things in python buffers:
:hook
(python-mode . anaconda-mode)
(python-mode . anaconda-eldoc-mode))
(use-package appt
;; keep track of appointments
:defer 2
:custom
(appt-delete-window-function (lambda () t))
(appt-disp-window-function #'my/appt-display)
(appt-display-interval 12 "Don't notify more than once")
(appt-message-warning-time 12)
(appt-display-mode-line nil)
:config
(defun my/appt-display (time-til _time msg)
(if (listp time-til)
(dotimes (i (length msg))
(alert (concat (nth i msg) " in " (nth i time-til) " minutes")
:title "Appt"))
(alert (concat msg " in " time-til " minutes") :title "Appt")))
(appt-activate))
(use-package async
;; Async is written to let things be more async-y in Emacs. I use it for
;; dired-async mode mostly.
:defer 1
:custom
(dired-async-message-function #'my/dired-async-message-function)
:config
(defun my/dired-async-message-function (text _face &rest args)
"Log messages from dired-async to messages buffer."
;; For whatever reason, the default for this *doesn't* log it to
;; *Messages*. Instead, it just displays the notification in the
;; mode line for 3 seconds, but if you type something it
;; immediately goes away. So just log it to *Messages* like a sane
;; person instead:
(message (format "Finished %s" (apply #'format text args))))
;; do dired actions asynchronously
(dired-async-mode))
(use-package auctex
;; AuCTeX is better than the built in tex mode; let's use it.
:load tex-site
:mode ("\\.tex\\'" . TeX-latex-mode)
:custom
(TeX-lisp-directory (expand-file-name "~/.emacs.d/lib/auctex"))
(TeX-data-directory (expand-file-name "~/.emacs.d/lib/auctex"))
(TeX-auto-save t)
(TeX-electric-escape t)
(TeX-electric-math '("\\(" . "\\)") "Smart $ behavior")
(TeX-electric-sub-and-superscript t)
(TeX-parse-self t)
(reftex-plug-into-AUCTeX t)
(TeX-source-correlate-method 'synctex)
(TeX-source-correlate-mode t)
(TeX-clean-confirm nil)
;; TeX-command-list by default contains a bunch of stuff I'll never
;; use. I use latexmk, xelatexmk, and View. That's pretty much it.
;; Maybe one day I'll add "clean" back to the list.
(TeX-command-list
'(("latexmk" "latexmk -synctex=1 -quiet -pdf %s"
TeX-run-compile nil t :help "Process file with latexmk")
("View" "%V" TeX-run-discard-or-function nil t :help "Run Viewer")
("xelatexmk" "latexmk -synctex=1 -quiet -xelatex %s"
TeX-run-compile nil t :help "Process file with xelatexmk")))
:hook
(LaTeX-mode . LaTeX-math-mode)
(LaTeX-mode . reftex-mode)
(LaTeX-mode . TeX-PDF-mode)
:config
(setq-default TeX-command-default "latexmk")
;; revert pdf from file after compilation finishes
(add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)
(use-package latex
:bind
(:map LaTeX-mode-map
("M-p" . outline-previous-visible-heading)
("M-n" . outline-next-visible-heading)
("<backtab>" . org-cycle))))
(use-package auth-source-pass
;; Integrate Emacs's builtin auth-source with pass:
:if (executable-find "pass")
:demand t
:config
(auth-source-pass-enable))
(use-package autoinsert
:defer 2
:config
(auto-insert-mode))
(use-package autorevert
:defer 1
:custom
(global-auto-revert-non-file-buffers t)
(auto-revert-verbose nil)
:config
;; Emacs should refresh buffers automatically so if they've changed on
;; disk the buffer will update.
(global-auto-revert-mode))
(use-package bibtex
:defer t ; built-in with Emacs
:custom
(bibtex-autokey-titleword-length 0)
(bibtex-autokey-titleword-separator "")
(bibtex-autokey-titlewords 0)
(bibtex-autokey-year-length 4)
(bibtex-autokey-year-title-separator "")
(bibtex-align-at-equal-sign t)
;; The default for bibtex-entry-format includes opts-or-alts, which deletes
;; empty entries. I want to keep those around, though, because a lot of
;; forthcoming articles get things like pages later:
(bibtex-entry-format '(required-fields numerical-fields))
(bibtex-files '("~/Sync/bibliography/references.bib"))
(bibtex-file-path "~/Sync/bibliography/references.bib")
:hook
(bibtex-mode . my/setup-bibtex-mode)
:config
(defun my/setup-bibtex-mode ()
"Set up bibtex mode."
(set-fill-column most-positive-fixnum))
(defun my/bibtex-generate-autokey ()
"This overwrites the bibtex-generate-autokey function that comes with Emacs.
I want my keys to be formatted: authornameYEAR, then a letter if there is already an entry that matches authornameYEAR."
(interactive)
;; first we delete the existing key
(bibtex-beginning-of-entry)
(re-search-forward bibtex-entry-maybe-empty-head)
(if (match-beginning bibtex-key-in-head)
(delete-region (match-beginning bibtex-key-in-head)
(match-end bibtex-key-in-head)))
(let* ((names (bibtex-autokey-get-names))
(year (bibtex-autokey-get-year))
(existing-keys (bibtex-parse-keys))
key)
(setq key (format "%s%s" names year))
(let ((ret key))
(cl-loop for c
from ?b to ?z
while (assoc ret existing-keys)
do (setq ret (format "%s%c" key c)))
ret)))
(advice-add #'bibtex-generate-autokey :override #'my/bibtex-generate-autokey))
(use-package browse-url
:defer t
:custom
;; Use Emacs' built in eww broswer (the Emacs Web Wowser!) by default.
;; browse-url-browser-function can take a list of regex's and associate a
;; specific browser with matches. So use eww for everything except a few
;; things that don't work well:
(browse-url-browser-function
'(("." . browse-url-firefox))))
(use-package calc
:defer t
:bind
(:map my/map
("C" . my/calc-eval-region))
:config
(defun my/calc-eval-region (arg)
"Evaluate an expression in calc and communicate the result.
If the region is active evaluate that, otherwise search backwards
to the first whitespace character to find the beginning of the
expression. By default, replace the expression with its value. If
called with the universal prefix argument, keep the expression
and insert the result into the buffer after it. If called with a
negative prefix argument, just echo the result in the
minibuffer."
(interactive "p")
(let (start end)
(if (use-region-p)
(setq start (region-beginning) end (region-end))
(progn
(setq end (point))
(setq start (search-backward-regexp "\\s-\\|\n" 0 1))
(setq start (1+ (if start start 0)))
(goto-char end)))
(let ((value (calc-eval (buffer-substring-no-properties start end))))
(pcase arg
(1 (delete-region start end))
(4 (insert " = ")))
(pcase arg
((or 1 4) (insert value))
(-1 (message value)))))))
(use-package calendar
;; Yes, my text editor comes with a calendar built in. Doesn't yours?
:defer t
:hook
;; make today easier to find, visually:
(calendar-today-visible . calendar-mark-today)
:config
(setq calendar-location-name "Austin")
(setq calendar-latitude [30 16 north])
(setq calendar-longitude [97 44 west])
;; Show holidays in the calendar
(setq calendar-mark-holidays-flag t)
;; Weeks start on Sunday
(setq calendar-week-start-day 0)
(setq calendar-date-display-form calendar-iso-date-display-form)
(calendar-set-date-style 'iso))
(use-package comint
:defer t
;; comint is the mode from which inferior processes inherit, like the
;; python REPL or iESS modes (the R console)
:config
(setq comint-move-point-for-output nil)
(setq comint-scroll-to-bottom-on-input 'this))
(use-package company
;; Company mode provides autocompletion of text and code.
:bind
(:map company-active-map
("C-s" . company-search-candidates)
("<tab>" . company-complete-common-or-cycle)
("RET" . company-complete-selection)
("C-n" . company-select-next)
("C-p" . company-select-previous))
:hook
(prog-mode . company-mode)
:custom
(company-idle-delay 0.25)
(company-require-match nil)
(company-minimum-prefix-length 2))
(use-package company-anaconda
;; company for integration with anaconda (loaded above)
:after (anaconda-mode company)
:config
(add-to-list 'company-backends 'company-anaconda))
(use-package compile
:defer t
:config
(setq compilation-ask-about-save nil)
(setq compilation-scroll-output 'first-error))
(use-package conf-mode
:mode (("\\.service\\'" . conf-unix-mode)
("\\.timer\\'" . conf-unix-mode)
("\\.target\\'" . conf-unix-mode)
("\\.mount\\'" . conf-unix-mode)
("\\.automount\\'" . conf-unix-mode)
("\\.slice\\'" . conf-unix-mode)
("\\.socket\\'" . conf-unix-mode)
("\\.path\\'" . conf-unix-mode)
("\\.netdev\\'" . conf-unix-mode)
("\\.network\\'" . conf-unix-mode)
("\\.link\\'" . conf-unix-mode)
("\\.automount\\'" . conf-unix-mode)))
(use-package csv-mode
;; Emacs can handle csv files with ease:
:defer)
(use-package custom
:no-require t
:defer t
:config
;; Don't write customization settings to init.el ... or anywhere else.
(setq custom-file null-device))
(use-package delsel
:defer 1
:config
;; Emacs by default doesn't replace selected text if you start typing
;; over it. Since that's the behavior of virtually all other programs,
;; let's make emacs do that too:
(delete-selection-mode))
(use-package diff-hl
:defer 15
;; highlight changes to files on the side
:hook
(magit-post-refresh . diff-hl-magit-post-refresh)
:config
(global-diff-hl-mode))
(use-package dired
;; Emacs can act as your file finder/explorer. Dired is the built-in way
;; to do this.
:defer t
:bind
(("C-x C-d" . dired) ; overrides list-directory, which I never use
:map dired-mode-map
("l" . dired-up-directory)) ; use l to go up in dired
:config
(setq dired-auto-revert-buffer t)
(setq dired-dwim-target t)
(setq dired-recursive-copies 'always)
(setq dired-recursive-deletes 'always)
;; -l: long listing format REQUIRED in dired-listing-switches
;; -a: show everything (including dotfiles)
;; -h: human-readable file sizes
(setq dired-listing-switches "-alh --group-directories-first")
(defun my/dired-ediff-marked ()
"Run `ediff' on two marked files in a dired buffer."
(interactive)
(unless (eq 'dired-mode major-mode)
(error "For use in dired buffers only"))
(let ((files (dired-get-marked-files)))
(when (not (eq 2 (length files)))
(error "Two files not marked"))
(ediff (car files) (nth 1 files)))))
(use-package dired-du
;; List directory sizes using du:
:bind
(:map dired-mode-map
("S" . dired-du-mode))
:custom
(dired-du-size-format t)
:hook
(dired-mode . my/dired-maybe-hide-details)
:config
(defun my/dired-maybe-hide-details ()
"Hide details (owner, permissions, etc) in dired unless dired-du-mode is active."
(unless dired-du-mode (dired-hide-details-mode))))
(use-package dired-x
:hook
(dired-load . (lambda () (load "dired-x")))
:bind
("C-x C-j" . dired-jump)
:custom
;; By default, dired asks you if you want to delete the dired buffer if
;; you delete the folder. I can't think of a reason I'd ever want to do
;; that.
(dired-clean-confirm-killing-deleted-buffers nil))
(use-package ediff
;; Ediff is great, but I have to tell it to use one frame (since I start
;; Emacs before X/wayland, it defaults to using two frames).
:defer t
:custom
(ediff-window-setup-function #'ediff-setup-windows-plain)
:hook
(ediff-prepare-buffer . my/ediff-prepare-buffer)
:config
(defun my/ediff-prepare-buffer ()
"Function to prepare ediff buffers.
Runs with `ediff-prepare-buffer-hook' so that it gets run on all
three ediff buffers (A, B, and C)."
(when (memq major-mode '(org-mode emacs-lisp-mode))
;; unfold org/elisp files
(outline-show-all))))
(use-package edit-indirect
;; Markdown relies on this package for to edit source code blocks like
;; org mode:
:defer t)
(use-package eldoc
;; eldoc shows useful information in the minibuffer and is enabled by
;; default.
:defer 1
:config
;; No need to delay showing eldoc
(setq eldoc-idle-delay 0))
(use-package elec-pair
:defer 1
:config
(electric-pair-mode))
(use-package electric-operator
;; Electric operator will turn ~a=10*5+2~ into ~a = 10 * 5 + 2~, so let's
;; enable it for R:
:hook
((ess-mode python-mode) . electric-operator-mode)
:custom
(electric-operator-R-named-argument-style 'spaced))
(use-package elfeed
;; Manage RSS and atom feeds from within Emacs!
:bind
(:map my/map
("s" . bjm/elfeed-load-db-and-open)
:map elfeed-search-mode-map
("l" . my/get-elfeed-log-buffer))
:custom
(elfeed-db-directory "~/Sync/.elfeed")
(elfeed-search-print-entry-function #'my/elfeed-print-entry)
:init
;; thanks -
;; http://pragmaticemacs.com/emacs/read-your-rss-feeds-in-emacs-with-elfeed/
;; though slightly modified functions to support syncing .elfeed between
;; machines makes sure elfeed reads index from disk before launching
(defun bjm/elfeed-load-db-and-open ()
"Load the elfeed db from disk before updating."
(interactive)
(elfeed)
(elfeed-db-load)
(elfeed-search-update--force)
(elfeed-update))
:hook
(elfeed-show-mode . my/setup-elfeed-show-mode)
(elfeed-search-mode . my/setup-elfeed-search-mode)
:config
(defun my/setup-elfeed-show-mode ()
"Setup `elfeed-show-mode'."
(setq-local shr-width 80)
;; Scale down huge images:
(setq-local shr-max-image-proportion 0.6))
(defun my/setup-elfeed-search-mode ()
"Setup `elfeed-search-mode'."
;; Don't use visual line mode in elfeed-search:
(visual-line-mode -1))
;; Overwrite the default print-entry function with one that prints date,
;; then feed-title, then title:
(defun my/elfeed-print-entry (entry)
"Print ENTRY to the buffer."
(let* ((date (elfeed-search-format-date (elfeed-entry-date entry)))
(title (or (elfeed-meta entry :title)
(elfeed-entry-title entry) ""))
(title-faces (elfeed-search--faces (elfeed-entry-tags entry)))
(title-column (elfeed-format-column
title (+ (window-width) (- 12) (- 12)) :left))
(feed (elfeed-entry-feed entry))
(feed-title
(when feed
(or (elfeed-meta feed :title) (elfeed-feed-title feed))))
(feed-column (elfeed-format-column
feed-title 10 :right)))
(insert (propertize date 'face 'elfeed-search-date-face) " ")
(when feed-title
(insert (propertize feed-column 'face 'elfeed-search-feed-face) " "))
(insert (propertize title-column 'face title-faces) " ")))
(defun my/get-elfeed-log-buffer ()
"Show elfeed log."
(interactive)
(switch-to-buffer-other-window (get-buffer "*elfeed-log*")))
(use-package elfeed-link))
(use-package elfeed-org
:after elfeed
:custom
(rmh-elfeed-org-files '("~/Sync/.elfeed/rmh-elfeed.org"))
:config
(elfeed-org))
(use-package elisp-mode
:defer t
:hook
;; Turn on flymake for emacs-lisp:
(emacs-lisp-mode . my/setup-emacs-lisp-mode)
:config
(defun my/setup-emacs-lisp-mode ()
"Setup stuff for elisp."
;; Sentences end with a double space in elisp:
(setq-local sentence-end-double-space t)))
(use-package emacsbug
:defer t
:custom
(report-emacs-bug-no-explanations t))
(use-package epkg
:defer t
:bind
("C-h P" . epkg-list-packages)
("C-h p" . epkg-describe-package)
:custom
(epkg-repository (expand-file-name "var/epkgs/" user-emacs-directory)))
(use-package erc
;; ERC is Emacs's client for IRC.
:if (executable-find "pass")
:commands (erc)
:custom
(erc-autojoin-channels-alist '(("freenode.net" "#emacs" "#archlinux")))
(erc-join-buffer 'bury)
(erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
(erc-port "6667")
(erc-server-reconnect-attempts 12)
(erc-server-reconnect-timeout 5)
(erc-nick "jabranham")
:hook
(erc-mode . goto-address-mode)
(erc-mode . erc-notifications-mode)
:config
;; Don't put this in :custom because it causes erc to get loaded.
(setq erc-server "irc.freenode.net"
erc-password (password-store-get "irc.freenode.net")))
(use-package eshell
;; Eshell is Emacs' built-in shell. You get UNIX-y goodness even on
;; Windows machines, plus it can evaluate elisp.
:defer t
:custom
(eshell-buffer-maximum-lines 20000 "Auto truncate after 20k lines")
(eshell-highlight-prompt nil "My prompt is easy enough to see")
(eshell-hist-ignoredups t "No duplicates in history")
(eshell-history-size 1024 "history size")
(eshell-list-files-after-cd t "List files after cd.")
(eshell-ls-initial-args "-ah" "Also list all files & human-readable filesizes.")
(eshell-plain-echo-behavior t "treat 'echo' like shell echo")
(eshell-prompt-function #'my/eshell-prompt)
(eshell-prompt-regexp "^λ ")
(eshell-scroll-to-bottom-on-input 'this)
(eshell-cmpl-cycle-completions nil)
:hook
;; Make urls clickable
(eshell-mode . goto-address-mode)
(eshell-mode . my/setup-eshell)
:bind
("C-c M-e" . eshell)
("C-c C-M-e" . my/eshell-remote)
:config
(defun my/eshell-remote (host)
"Open eshell on a remote host.
Uses `pcmpl-ssh-config-hosts' to obtain a list of possible hosts."
(interactive
(list
(completing-read "Host: " (pcmpl-ssh-config-hosts))))
(eshell)
(setq default-directory (concat "/ssh:" host ":"))
(eshell-reset))
(defun my/setup-eshell ()
"Set up eshell how I want. To be called by `eshell-mode-hook'."
(progn
(eshell-cmpl-initialize)
(define-key eshell-mode-map [remap eshell-pcomplete] 'helm-esh-pcomplete)
(unbind-key "M-s" eshell-mode-map)
(bind-key "M-r" #'helm-eshell-history eshell-mode-map)))
(use-package pcomplete-extension
:demand t)
(defun my/eshell-prompt ()
"Function that determines the eshell prompt. Must set
`eshell-prompt-function' to this for it to work."
(let ((path (abbreviate-file-name (eshell/pwd))))
(concat
;; working directory
(format (propertize "(%s)")
(propertize path 'face '(:inherit eshell-prompt)))
;; git info
(when (and (fboundp #'magit-get-current-branch) ; magit might not be loaded yet
(magit-get-current-branch))
(format (propertize "@%s")
(propertize (magit-get-current-branch) 'face '(:foreground "light slate grey"))))
;; newline, then prompt
(propertize "\nλ" 'face '(:inherit eshell-prompt))
;; need to have a space, otherwise the first text I type gets
;; propertized to match λ:
" "))))
(use-package esh-module
:defer t
:config
;; Don't show the welcome message banner:
(delq 'eshell-banner eshell-modules-list)
;; use TRAMP sudo method to avoid retyping sudo password on multiple calls:
(push 'eshell-tramp eshell-modules-list))
(use-package ess-r-mode
;; ESS (Emacs Speaks Statistics) is a great project that makes Emacs
;; speak with R and other statistical languages
:bind
(:map ess-mode-map
("M-=" . ess-insert-S-assign)
("M-p" . my/add-pipe)
("C-|" . my/ess-eval-pipe-through-line)
:map inferior-ess-mode-map
("M-=" . ess-insert-S-assign))
:custom
(ess-ask-for-ess-directory nil "Don't ask for dir when starting a process")
(ess-default-style 'RStudio)
(ess-eldoc-show-on-symbol t "Show eldoc on symbol instead of only inside of parens")
(ess-eval-visibly 'nowait "Don't hog Emacs")
(ess-history-directory (concat user-emacs-directory "var/Rhist/") "Save R history in one place rather than making .Rhistory files everywhere.")
(ess-pdf-viewer-pref "emacsclient")
(ess-use-ido nil "I prefer helm.")
(ess-plain-first-buffername nil "Name first R process R:1")
(ess-nuke-trailing-whitespace-p t)
(ess-R-font-lock-keywords
'((ess-R-fl-keyword:modifiers . t)
(ess-R-fl-keyword:fun-defs . t)
(ess-R-fl-keyword:keywords . t)
(ess-R-fl-keyword:assign-ops . t)
(ess-R-fl-keyword:constants . t)
(ess-fl-keyword:fun-calls . nil)
(ess-fl-keyword:numbers . t)
(ess-fl-keyword:operators . t)
(ess-fl-keyword:delimiters . nil)
(ess-fl-keyword:= . t)
(ess-R-fl-keyword:F&T . t)))
(inferior-R-font-lock-keywords
'((ess-S-fl-keyword:prompt . t)
(ess-R-fl-keyword:messages . t)
(ess-R-fl-keyword:modifiers . t)
(ess-R-fl-keyword:fun-defs . t)
(ess-R-fl-keyword:keywords . t)
(ess-R-fl-keyword:assign-ops . t)
(ess-R-fl-keyword:constants . t)
(ess-fl-keyword:matrix-labels . t)
(ess-fl-keyword:fun-calls . nil)
(ess-fl-keyword:numbers . nil)
(ess-fl-keyword:operators . t)
(ess-fl-keyword:delimiters . nil)
(ess-fl-keyword:= . t)
(ess-R-fl-keyword:F&T . t)))
:hook
(ess-r-post-run . my/ess-execute-screen-options)
:config
(setq ess-write-to-dribble nil)
;; Make that folder if needed.
(mkdir ess-history-directory t)
(defalias 'ess-smart-S-assign #'self-insert-command)
(defun my/add-pipe ()
"Add a pipe operator %>% at the end of the current line.
Don't add one if the end of line already has one. Ensure one
space to the left and start a newline with indentation."
(interactive)
(end-of-line)
(unless (looking-back "%>%" nil)
(just-one-space 1)
(insert "%>%"))
(newline-and-indent))
(defun my/ess-execute-screen-options ()
"Call `ess-execute-screen-options' invisibly."
(ess-execute-screen-options t))
;; I sometimes want to evaluate just part of a piped sequence. The
;; following lets me do so without needing to insert blank lines or
;; something:
(defun my/ess-beginning-of-pipe-or-end-of-line ()
"Find point position of end of line or beginning of pipe %>%."
(if (search-forward "%>%" (line-end-position) t)
(let ((pos (progn
(beginning-of-line)
(search-forward "%>%" (line-end-position))
(backward-char 3)
(point))))
(goto-char pos))
(end-of-line)))
(defun my/ess-eval-pipe-through-line (vis)
"Like `ess-eval-paragraph' but only evaluates up to the pipe on this line.
If no pipe, evaluate paragraph through the end of current line.
Prefix arg VIS toggles visibility of ess-code as for `ess-eval-region'."
(interactive "P")
(save-excursion
(let ((end (progn
(my/ess-beginning-of-pipe-or-end-of-line)
(point)))
(beg (progn (backward-paragraph)
(ess-skip-blanks-forward 'multiline)
(point))))
(ess-eval-region beg end vis)))))
(use-package exec-path-from-shell
;; This ensures Emacs has the same PATH as the rest of my system. It is
;; necessary for macs (not that I ever use that), or if Emacs is started
;; via a systemd service, as systemd user services don't inherit the
;; environment of that user
:if (or (eq system-type 'darwin)
(and (daemonp)
(eq system-type 'gnu/linux)))
:config
(exec-path-from-shell-initialize))
(use-package executable
:hook
;; Emacs can set file permissions automatically. Make scripts executable
;; so I don't have to remember to do so:
(after-save . executable-make-buffer-file-executable-if-script-p))
(use-package eww
:commands (eww eww-search-words)
:bind
;; If a webpage requires more than eww can handle, I can switch to the
;; system default by tapping &, but 0 is easier to type:
(:map eww-mode-map
("0" . eww-browse-with-external-browser)))
(use-package exwm
;; EXWM makes Emacs your window manager. It works surprising well. I've
;; used Gnome and i3 and neither of them seems as intuitive or as stable
;; as EXWM.
:demand t
:if (getenv "EXWM")
:custom
;; show all X windows in all workspaces
(exwm-workspace-show-all-buffers t)
(exwm-layout-show-all-buffers t)
(exwm-input-simulation-keys
;; simulation keys so that e.g. `C-n' goes down in most X applications
'(([?\C-b] . left)
([?\C-f] . 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))))
;; Keybindings that exwm won't pass on to X windows:
(exwm-input-global-keys
`((,(kbd "s-r") . exwm-reset)
(,(kbd "s-t") . exwm-workspace-swap)
,@(mapcar (lambda (i)
`(,(kbd (format "s-%d" i)) .
(lambda ()
(interactive)
(exwm-workspace-switch-create ,i))))
(number-sequence 0 9))
(,(kbd "s-d") . my/application-launch)
(,(kbd "<XF86AudioMute>") . my/mute)
(,(kbd "<XF86AudioRaiseVolume>") . my/volume-up)
(,(kbd "<XF86AudioLowerVolume>") . my/volume-down)
(,(kbd "<XF86AudioMicMute>") . my/mute-mic)
(,(kbd "s-l") . my/lock-screen)
(,(kbd "<s-print>") . my/take-screenshot)
(,(kbd "s-p") . helm-pass)))
:hook
(after-init . my/start-background-programs)
(exwm-floating-exit . exwm-layout-show-mode-line)
(exwm-floating-setup . exwm-layout-hide-mode-line)
(exwm-manage-finish . my/exwm-manage)
(exwm-update-class . my/update-class-name)
(exwm-update-title . my/exwm-rename-buffer-to-title)
:bind
(:prefix-map my/power-menu-map
:prefix "s-C"
("e" . save-buffers-kill-emacs)
("l" . my/lock-screen)
("s" . my/system-suspend)
("r" . my/system-reboot))
(:map exwm-mode-map
;; Use C-q to sent next key to X application literally.
("C-q" . exwm-input-send-next-key))
:config
;; Setting this to 0 makes windowing events much snappier
(setq x-wait-for-event-timeout 0)
;; Create all 10 workspaces on startup. This increases startup time a
;; bit, but if I try to switch to a workspace that doesn't exist it
;; messes up the window configuration.
(setq exwm-workspace-number 10)
;; Make class name the buffer name
(defun my/update-class-name ()
"Update X class name of buffer."
(exwm-workspace-rename-buffer exwm-class-name))
(defun my/application-launch (&optional command)
(interactive (list (read-shell-command "$ ")))
(start-process-shell-command command nil command))
(defun my/exwm-manage ()
"Setup X applications."
(when (string= "Firefox" exwm-class-name)
(exwm-layout-hide-mode-line)))
(defun my/exwm-rename-buffer-to-title ()
"Rename buffer to `exwm-title'"
(when (string= "qutebrowser" exwm-class-name)
(exwm-workspace-rename-buffer exwm-title)))
(defun my/mute ()
"Mute"
(interactive)
(start-process "" nil "pactl" "set-sink-mute" "0" "toggle"))
(defun my/volume-up ()
"Volume up"
(interactive)
(start-process "" nil "pactl" "set-sink-volume" "0" "+5%"))
(defun my/volume-down ()
"Volume down"
(interactive)
(start-process "" nil "pactl" "set-sink-volume" "0" "-5%"))
(defun my/mute-mic ()
"Toggle mic mute status"
(interactive)
(start-process "" nil "pactl" "set-source-mute" "1" "toggle"))
(defun my/lock-screen ()
"Lock screen"
(interactive)
(shell-command "i3lock -c 000000"))
(defun my/system-suspend ()
"Suspend system."
(interactive)
(when (y-or-n-p "Suspend system? ")
(shell-command "systemctl suspend")))
(defun my/system-reboot ()
"Reboot system."
(interactive)
(when (y-or-n-p "Reboot system? ")
(shell-command "systemctl reboot")))
(defun my/take-screenshot (&optional arg)
"Take a screenshot.
With ARG, take an area-selection screenshot."
(interactive "P")
(mkdir "~/Pictures/screenshots/" t)
(start-process-shell-command
"scrot" nil
(concat "scrot " (when arg "-s ")
"-z " ; no beeping
"~/Pictures/screenshots/screenshot_%Y%m%d_%H%M%S.png")))
;; Start some daemons:
(defun my/start-background-programs ()
"Start some processes. Hooks into `after-init-hook'."
(make-process
:name "NM-applet" :buffer nil
:command '("nm-applet") ; Networkmanager
:noquery t)
(make-process
:name "Power Manager" :buffer nil
:command '("xfce4-power-manager"); power info & screen brightness
:noquery t)
(make-process
:name "Syncthing" :buffer nil
:command '("syncthing-gtk" "--minimized") ; syncthing
:noquery t)
(make-process
:name "Redshift" :buffer nil
;; redshift in evenings to reduce eye strain
:command '("systemctl" "--user" "start" "redshift.service"))
(when (string= (system-name) "earth")
(setenv "allow_rgb10_configs" "false"))
(make-process
:name "Compton" :buffer nil
:command '("compton" "--no-fading-openclose")
:noquery t))
;; Enable EXWM
(exwm-enable))
(use-package exwm-randr
;; Xrandr (multi-screen)
:after exwm
;; Only load if I'm on my laptop:
:if (string= (system-name) "mars")
:demand t
:custom
(exwm-randr-workspace-output-plist '(0 "eDP-1"
1 "DP-2"
2 "HDMI-1"))
:hook
(exwm-randr-screen-change . my/exwm-manage-screens)
:config
(defun my/exwm-manage-screens ()
"Manage screen placement.
To be added to `exwm-randr-screen-change-hook'."
(start-process-shell-command
"xrandr" nil "xrandr --output DP-2 --right-of eDP-1 --auto --output HDMI-1 --left-of eDP-1 --auto"))
(exwm-randr-enable))
(use-package faces
;; faces are how Emacs determines how to display characters (font, size,
;; color, etc)
:defer t
:bind
("C-h c" . describe-face) ; overrides describe-key-briefly from help.el
:custom-face
(fixed-pitch-serif ((t (:font "Symbola"))))
:config
(add-to-list 'default-frame-alist
'(font . "monospace-12")))
(use-package face-remap
:bind
;; Everywhere else you can zoom with C-- and C-+. Let's make Emacs
;; follow that convention:
("C-=" . text-scale-increase)
("C-+" . text-scale-increase)
("C--" . text-scale-decrease))
(progn ; `files.el'