forked from shanhaiying/.emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
2662 lines (2250 loc) · 90.6 KB
/
init.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; init.el --- Emacs configuration of Sebastian Wiesner -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2012-2016 Sebastian Wiesner <swiesner@lunaryorn.com>
;;
;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
;; URL: https://gihub.com/lunaryorn/.emacs.d
;; Keywords: convenience
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free Software
;; Foundation; either version 3 of the License, or (at your option) any later
;; version.
;; This program is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
;; details.
;; You should have received a copy of the GNU General Public License along with
;; GNU Emacs; see the file COPYING. If not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;; USA.
;;; Commentary:
;; Emacs configuration of Sebastian Wiesner, functional programmer and Flycheck
;; maintainer.
;;; Code:
;; Increase GC threshold to make init.el load faster
(defvar lunaryorn-default-gc-cons-threshold gc-cons-threshold)
(setq gc-cons-threshold 100000000)
;;; Debugging
(setq message-log-max 10000)
;;; Package management
;; Please don't load outdated byte code
(setq load-prefer-newer t)
(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives
;; Package archives, the usual suspects
'(("GNU ELPA" . "http://elpa.gnu.org/packages/")
("MELPA Stable" . "https://stable.melpa.org/packages/")
("MELPA" . "https://melpa.org/packages/"))
;; Prefer MELPA Stable over GNU over MELPA. IOW prefer MELPA's stable
;; packages over everything and only fall back to GNU or MELPA if
;; necessary.
package-archive-priorities
'(("MELPA Stable" . 10)
("GNU ELPA" . 5)
("MELPA" . 0))
;; Pin a couple of packages to MELPA
package-pinned-packages
'(;; I maintain these and know what changes
("flycheck" . "MELPA")
;; Last release was a long time ago for these
("ivy" . "MELPA")
("ivy-hydra" . "MELPA")
("counsel" . "MELPA")
("swiper" . "MELPA")))
(package-initialize)
;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
;;; Requires
(require 'use-package)
(require 'subr-x)
(require 'time-date)
;;; Initialization
(when (version< emacs-version "25")
(warn "This configuration needs Emacs trunk, but this is %s!" emacs-version))
;; And disable the site default settings
(setq inhibit-default-init t)
(defun lunaryorn-snapshot-version-p (version)
"Whether VERSION is an Emacs snapshot version."
(pcase-let ((`(,_ ,_ ,build) (version-to-list version)))
;; Snapshots with build numbers > 90 are pretests which come from proper
;; release tarballs and don't need to be rebuild weekly
(and (>= build 50) (<= build 90))))
(when (lunaryorn-snapshot-version-p emacs-version)
;; When on a snapshot version, warn if the build is older than a week to
;; ensure that we stay up to date.
(run-with-idle-timer
2 nil
(lambda ()
(let ((time-since-build (time-subtract (current-time) emacs-build-time)))
(when (> (time-to-number-of-days time-since-build) 7)
(lwarn 'emacs :warning "Your Emacs build is more than a week old!"))))))
(defun lunaryorn-check-version-of-emacs-executable ()
"Check the `emacs' executable in $PATH.
Warn if the executable is missing, or has the wrong version,
which happens with Emacs for Mac OS X if you forget to install
the command line runner."
(if-let ((executable (executable-find "emacs")))
(let ((version (car (process-lines executable "--version"))))
(unless (string-match-p (concat "GNU Emacs "
(regexp-quote emacs-version))
version)
(lwarn 'emacs :warning
"Running Emacs %s but the Emacs executable at %s is %s"
emacs-version executable version)))
(lwarn 'emacs :warning "No Emacs executable in $PATH!")))
(run-with-idle-timer 1 nil #'lunaryorn-check-version-of-emacs-executable)
(add-hook 'after-init-hook (lambda () (message "Time to load init file: %s"
(emacs-init-time))))
;;; Customization
(use-package validate ; Validate options
:ensure t)
(defconst lunaryorn-custom-file (locate-user-emacs-file "custom.el")
"File used to store settings from Customization UI.")
(use-package cus-edit
:defer t
:config
(validate-setq
custom-file lunaryorn-custom-file
custom-buffer-done-kill nil ; kill when existing
custom-buffer-verbose-help nil ; Remove redundant help text
;; Show me the real variable name
custom-unlispify-tag-names nil
custom-unlispify-menu-entries nil)
:init (load lunaryorn-custom-file 'no-error 'no-message))
;;; Environment fixup
(use-package exec-path-from-shell
:ensure t
:if (and (eq system-type 'darwin) (display-graphic-p))
:config
(progn
(when (string-match-p "/zsh$" (getenv "SHELL"))
;; Use a non-interactive login shell. A login shell, because my
;; environment variables are mostly set in `.zprofile'.
(validate-setq exec-path-from-shell-arguments '("-l")))
(validate-setq exec-path-from-shell-variables
'("PYTHONPATH" ; Python modules
"JAVA_OPTS" ; Options for java processes
"SBT_OPTS" ; Options for SBT
"RUST_SRC_PATH" ; Rust sources, for racer
"CARGO_HOME" ; Cargo home, for racer
"EMAIL" ; My personal email
"PATH" ; Executables
"INFOPATH" ; Info directories
"MANPATH" ; Man pages
))
;; Initialize Emacs' environment from the shell
(exec-path-from-shell-initialize)
;; Tell Emacs about my email address
(validate-setq user-mail-address (getenv "EMAIL"))
;; Re-initialize the `Info-directory-list' from $INFOPATH. Since package.el
;; already initializes info, we need to explicitly add the $INFOPATH
;; directories to `Info-directory-list'. We reverse the list of info paths
;; to prepend them in proper order subsequently
(with-eval-after-load 'info
(dolist (dir (nreverse (parse-colon-path (getenv "INFOPATH"))))
(when dir
(add-to-list 'Info-directory-list dir))))))
;;; OS X support
(when (eq system-type 'darwin)
(validate-setq
mac-option-modifier 'meta ; Option is simply the natural Meta
mac-command-modifier 'meta ; But command is a lot easier to hit
mac-right-command-modifier 'left
;; FIXME: Temporarily bind right alt to control until karabiner works again
;; on macOS sierra and gives me by beloved return/control key combination
;; back
mac-right-option-modifier 'control ; Keep right option for accented input
;; Just in case we ever need these keys
mac-function-modifier 'hyper))
(use-package ns-win ; OS X window support
:defer t
:if (eq system-type 'darwin)
:config
(validate-setq
;; Don't pop up new frames from the workspace
ns-pop-up-frames nil))
(use-package lunaryorn-osx ; Personal OS X tools
:if (eq system-type 'darwin)
:load-path "lisp/"
:defer t)
(use-package osx-trash ; Trash support for OS X
:if (eq system-type 'darwin)
:ensure t
:init (osx-trash-setup))
;;; Fonts
(set-face-attribute 'default nil
:family "Source Code Pro" :height 120)
(set-face-attribute 'variable-pitch nil
:family "Fira Sans" :height 130 :weight 'regular)
(use-package face-remap ; Face remapping
:bind (("C-c w z" . text-scale-adjust)))
;;; User interface
;; Get rid of tool bar, menu bar and scroll bars. On OS X we preserve the menu
;; bar, since the top menu bar is always visible anyway, and we'd just empty it
;; which is rather pointless.
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
(when (and (not (eq system-type 'darwin)) (fboundp 'menu-bar-mode))
(menu-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
;; No blinking and beeping, no startup screen, no scratch message and short
;; Yes/No questions.
(blink-cursor-mode -1)
(validate-setq ring-bell-function #'ignore
inhibit-startup-screen t
initial-scratch-message "Hello there!\n")
(fset 'yes-or-no-p #'y-or-n-p)
;; Opt out from the startup message in the echo area by simply disabling this
;; ridiculously bizarre thing entirely.
(fset 'display-startup-echo-area-message #'ignore)
;; Insert my logo into scratch <3
(add-hook 'after-init-hook
(lambda ()
(with-current-buffer "*scratch*"
(goto-char (point-min))
(insert-image (create-image (locate-user-emacs-file "logo.png"))
"logo")
(insert "\n"))))
(use-package solarized ; My colour theme
:ensure solarized-theme
:config
;; Disable variable pitch fonts in Solarized theme
(validate-setq
solarized-use-variable-pitch nil
;; Prefer italics over bold
solarized-use-less-bold t
solarized-use-more-italic t
solarized-distinct-doc-face t ; Emphasize docstrings
;; I find different font sizes irritating.
solarized-height-minus-1 1.0
solarized-height-plus-1 1.0
solarized-height-plus-2 1.0
solarized-height-plus-3 1.0
solarized-height-plus-4 1.0)
(load-theme 'solarized-light 'no-confirm))
(bind-key "C-c t V" #'variable-pitch-mode)
(use-package page-break-lines ; Turn page breaks into lines
:ensure t
:init (global-page-break-lines-mode)
:diminish page-break-lines-mode)
(use-package beacon ; Highlight cursor position in buffer
:disabled t
:ensure t
:init (beacon-mode 1)
:diminish beacon-mode)
(use-package stripe-buffer ; Add stripes to a buffer
:ensure t
:init (add-hook 'dired-mode-hook #'stripe-buffer-mode))
;;; Keys and key bindings
;; Our key bindings are solely in the user space C-c <letter>. The list of
;; which-key prefixes documents the meaning of specific key prefixes, such as
;; C-c f for file commands. C-c m is special in that it always holds commands
;; that are only for the current major mode. The mode-specific which-key
;; prefixes document the individual bindings for major modes under C-c m.
;;
;; We may also bind F5 to F9. Since we can't document these in code, the
;; following list shows their abstract meanings:
;;
;; * F5: Compile
;; * F6: n/a
;; * F7: n/a
;; * F8: n/a
;; * F9: n/a
;;
;; All of these keys have default global bindings, but major and minor modes may
;; override them if there's a better command for the specific purpose available.
;;
;; Note that the notation for the function keys is <f5>, i.e. the lowercase name
;; surrounded by angle brackets.
(use-package which-key ; Show help popups for prefix keys
:ensure t
:init (which-key-mode)
:config
(validate-setq
which-key-idle-delay 0.4
which-key-sort-order 'which-key-prefix-then-key-order
;; Let's go unicode :)
which-key-key-replacement-alist
'(("<\\([[:alnum:]-]+\\)>" . "\\1")
("up" . "↑")
("right" . "→")
("down" . "↓")
("left" . "←")
("DEL" . "⌫")
("deletechar" . "⌦")
("RET" . "⏎"))
which-key-description-replacement-alist
'(("Prefix Command" . "prefix")
;; Lambdas
("\\`\\?\\?\\'" . "λ")
;; Prettify hydra entry points
("/body\\'" . "|=")
;; Drop/shorten package prefixes
("\\`lunaryorn-" . "")
("projectile-" . "proj-")
("magit-" . "ma-")))
(which-key-add-key-based-replacements
;; Prefixes for global prefixes and minor modes
"C-c @" "outline"
"C-c !" "flycheck"
"C-c 8" "typo"
"C-c 8 -" "typo/dashes"
"C-c 8 <" "typo/left-brackets"
"C-c 8 >" "typo/right-brackets"
;; Prefixes for my personal bindings
"C-c a" "applications"
"C-c b" "buffers"
"C-c c" "compile-and-comments"
"C-c e" "errors"
"C-c f" "files"
"C-c f v" "variables"
"C-c g" "git"
"C-c g g" "github/gist"
"C-c h" "help"
"C-c i" "insert"
"C-c i l" "licenses"
"C-c j" "jump"
"C-c l" "language/spelling"
"C-c m" "major mode"
"C-c o" "cursors"
"C-c o i" "cursors/insert"
"C-c p" "projects"
"C-c p s" "projects/search"
"C-c p x" "projects/execute"
"C-c p 4" "projects/other-window"
"C-c s" "search"
"C-c t" "toggle"
"C-c w" "windows/frames"
"C-c x" "text")
;; Prefixes for major modes
(which-key-add-major-mode-key-based-replacements 'markdown-mode
"C-c TAB" "markdown/images"
"C-c C-a" "markdown/links"
"C-c C-c" "markdown/process"
"C-c C-s" "markdown/style"
"C-c C-t" "markdown/header"
"C-c C-x" "markdown/structure"
"C-c m" "markdown/personal")
(which-key-add-major-mode-key-based-replacements 'emacs-lisp-mode
"C-c m" "elisp/personal"
"C-c m e" "eval")
(which-key-add-major-mode-key-based-replacements 'js2-mode
"C-c m" "js/personal"
"C-c m r" "refactor")
(which-key-add-major-mode-key-based-replacements 'scala-mode
"C-c C-b" "ensime/build"
"C-c C-d" "ensime/debug"
"C-c C-r" "ensime/refactor"
"C-c C-v" "ensime/misc"
"C-c m" "scala/personal"
"C-c m b" "scala/build")
(which-key-add-major-mode-key-based-replacements 'haskell-mode
"C-c m" "haskell/personal"
"C-c m i" "haskell/imports")
(which-key-add-major-mode-key-based-replacements 'rust-mode
"C-c C-c" "rust/cargo")
(which-key-add-major-mode-key-based-replacements 'web-mode
"C-c C-a" "web/attributes"
"C-c C-b" "web/blocks"
"C-c C-d" "web/dom"
"C-c C-e" "web/element"
"C-c C-t" "web/tags")
:diminish which-key-mode)
(use-package hydra ; Bindings that stick
:ensure t)
;; Package manager and init file
(use-package paradox ; Better package menu
:ensure t
:bind (("C-c a p" . paradox-list-packages)
("C-c a P" . paradox-upgrade-packages))
:config
(validate-setq
paradox-execute-asynchronously nil ; No async update, please
paradox-spinner-type 'moon ; Fancy spinner
;; Show all possible counts
paradox-display-download-count t
paradox-display-star-count t
;; Don't star automatically
paradox-automatically-star nil
;; Hide download button, and wiki packages
paradox-use-homepage-buttons nil ; Can type v instead
paradox-hide-wiki-packages t))
(use-package bug-hunter ; Search init file for bugs
:ensure t)
;;; The mode line
(line-number-mode)
(column-number-mode)
(use-package anzu ; Position/matches count for isearch
:ensure t
:defer 1
:bind
(([remap query-replace] . anzu-query-replace)
([remap query-replace-regexp] . anzu-query-replace-regexp)
:map isearch-mode-map
([remap isearch-query-replace] . anzu-isearch-query-replace)
([remap isearch-query-replace-regexp] . anzu-isearch-query-replace-regexp))
:config
(global-anzu-mode)
(setq anzu-cons-mode-line-p nil)
:diminish anzu-mode)
(use-package which-func ; Current function name
:defer 1
:config
(which-function-mode)
(validate-setq
which-func-unknown "⊥" ; The default is really boring…
which-func-format
`((:propertize (" ➤ " which-func-current)
local-map ,which-func-keymap
face which-func
mouse-face mode-line-highlight
help-echo "mouse-1: go to beginning\n\
mouse-2: toggle rest visibility\n\
mouse-3: go to end"))))
(use-package spaceline-config ; A beautiful mode line
:ensure spaceline
:config
(spaceline-compile
'lunaryorn
;; Left side of the mode line (all the important stuff)
'(((buffer-modified buffer-size input-method) :face highlight-face)
anzu
'(buffer-id remote-host buffer-encoding-abbrev)
((point-position line-column buffer-position selection-info)
:separator " | ")
major-mode
process
(flycheck-error flycheck-warning flycheck-info)
(python-pyvenv :fallback python-pyenv)
((which-function projectile-root) :separator " @ ")
((minor-modes :separator spaceline-minor-modes-separator) :when active))
;; Right segment (the unimportant stuff)
'((version-control :when active)))
(setq-default mode-line-format '("%e" (:eval (spaceline-ml-lunaryorn)))))
(use-package powerline ; The work-horse of Spaceline
:ensure t
:after spaceline-config
:config (validate-setq
powerline-height (truncate (* 1.0 (frame-char-height)))
powerline-default-separator 'utf-8))
;;; Minibuffer
(validate-setq
history-length 1000 ; Store more history
use-dialog-box nil ; Never use dialogs for minibuffer input
)
(use-package savehist ; Save minibuffer history
:init (savehist-mode t)
:config (validate-setq savehist-save-minibuffer-history t
savehist-autosave-interval 180))
(use-package ivy ; Minibuffer completion
:ensure t
:init (ivy-mode 1)
:bind (("C-c b r" . ivy-resume))
:config
;; Include recentf and bookmarks to switch buffer, and tune the count format.
(validate-setq ivy-use-virtual-buffers t
ivy-count-format "(%d/%d) ")
:diminish ivy-mode)
(use-package ivy-hydra ; Hydra bindings for ivy buffer
:ensure t
:after ivy
:bind (:map ivy-minibuffer-map
("C-o" . hydra-ivy/body)))
(use-package counsel ; Ivy-powered commands
:ensure t
:init (counsel-mode)
:bind (([remap execute-extended-command] . counsel-M-x)
([remap find-file] . counsel-find-file)
([remap describe-function] . counsel-describe-function)
([remap describe-variable] . counsel-describe-variable)
([remap info-lookup-symbol] . counsel-info-lookup-symbol)
([remap completion-at-point] . counsel-company)
("C-c f L" . counsel-load-library)
("C-c f r" . counsel-recentf)
("C-c i 8" . counsel-unicode-char)
("C-c s a" . counsel-ag)
("C-c j t" . counsel-imenu)
("C-c g L" . counsel-git-log)))
;;; Buffer, Windows and Frames
(validate-setq
frame-resize-pixelwise t ; Resize by pixels
frame-title-format
'(:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name)) "%b"))
;; Size new windows proportionally wrt other windows
window-combination-resize t)
(setq-default line-spacing 0.2) ; A bit more spacing between lines
(defun lunaryorn-display-buffer-fullframe (buffer alist)
"Display BUFFER in fullscreen.
ALIST is a `display-buffer' ALIST.
Return the new window for BUFFER."
(let ((window (display-buffer-pop-up-window buffer alist)))
(when window
(delete-other-windows window))
window))
;; Configure `display-buffer' behaviour for some special buffers.
(validate-setq
display-buffer-alist
`(
;; Put REPLs and error lists into the bottom side window
(,(rx bos
(or "*Help" ; Help buffers
"*Warnings*" ; Emacs warnings
"*Compile-Log*" ; Emacs byte compiler log
"*compilation" ; Compilation buffers
"*Flycheck errors*" ; Flycheck error list
"*shell" ; Shell window
"*sbt" ; SBT REPL and compilation buffer
"*ensime-update*" ; Server update from Ensime
"*SQL" ; SQL REPL
"*Cargo" ; Cargo process buffers
(and (1+ nonl) " output*") ; AUCTeX command output
))
(display-buffer-reuse-window
display-buffer-in-side-window)
(side . bottom)
(reusable-frames . visible)
(window-height . 0.33))
;; Let `display-buffer' reuse visible frames for all buffers. This must
;; be the last entry in `display-buffer-alist', because it overrides any
;; later entry with more specific actions.
("." nil (reusable-frames . visible))))
(use-package frame ; Frames
:bind (("C-c w F" . toggle-frame-fullscreen))
:init (progn
;; Kill `suspend-frame'
(global-set-key (kbd "C-z") nil)
(global-set-key (kbd "C-x C-z") nil))
:config (add-to-list 'initial-frame-alist '(fullscreen . maximized)))
(use-package focus-autosave-mode ; Save buffers when focus is lost
:ensure t
:init (focus-autosave-mode)
:diminish focus-autosave-mode)
(use-package lunaryorn-buffers ; Personal buffer tools
:load-path "lisp/"
:defer t ; Prevent a mysterious recursive load error
:bind (("C-c b k" . lunaryorn-kill-this-buffer))
:config
(add-hook 'kill-buffer-query-functions
#'lunaryorn-do-not-kill-important-buffers))
(use-package uniquify ; Make buffer names unique
:config (validate-setq uniquify-buffer-name-style 'forward))
(use-package ibuffer ; Better buffer list
:bind (([remap list-buffers] . ibuffer))
;; Show VC Status in ibuffer
:config
(validate-setq
ibuffer-formats
'((mark modified read-only vc-status-mini " "
(name 18 18 :left :elide)
" "
(size 9 -1 :right)
" "
(mode 16 16 :left :elide)
" "
(vc-status 16 16 :left)
" "
filename-and-process)
(mark modified read-only " "
(name 18 18 :left :elide)
" "
(size 9 -1 :right)
" "
(mode 16 16 :left :elide)
" " filename-and-process)
(mark " " (name 16 -1) " " filename))))
(use-package ibuffer-vc ; Group buffers by VC project and status
:ensure t
:defer t
:init (add-hook 'ibuffer-hook
(lambda ()
(ibuffer-vc-set-filter-groups-by-vc-root)
(unless (eq ibuffer-sorting-mode 'alphabetic)
(ibuffer-do-sort-by-alphabetic)))))
(use-package ibuffer-projectile ; Group buffers by Projectile project
:ensure t
:disabled t
:defer t
:init (add-hook 'ibuffer-hook #'ibuffer-projectile-set-filter-groups))
;; Standard window commands
(bind-key "C-c w =" #'balance-windows)
(bind-key "C-c w k" #'delete-window)
(bind-key "C-c w /" #'split-window-right)
(bind-key "C-c w -" #'split-window-below)
(bind-key "C-c w m" #'delete-other-windows)
(use-package lunaryorn-window ; Personal window utilities
:load-path "lisp/"
:defer t
:bind (("C-c w q" . lunaryorn-quit-all-side-windows)
("C-c w d" . lunaryorn-toggle-current-window-dedication)
("C-c w b" . lunaryorn-switch-to-minibuffer-window)))
(use-package windmove ; Move between windows with Shift+Arrow
:bind (("C-c w <left>" . windmove-left)
("C-c w <right>" . windmove-right)
("C-c w <up>" . windmove-up)
("C-c w <down>" . windmove-down)))
(use-package winner ; Undo and redo window configurations
:init (winner-mode))
(use-package ace-window ; Fast window switching
:ensure t
:bind (("C-x o" . ace-window)
("C-c w w" . ace-window)))
(use-package golden-ratio ; Automatically resize windows
:ensure t
:init
(defun lunaryorn-toggle-golden-ratio ()
(interactive)
(if (bound-and-true-p golden-ratio-mode)
(progn
(golden-ratio-mode -1)
(balance-windows))
(golden-ratio-mode)
(golden-ratio)))
:bind (("C-c t g" . lunaryorn-toggle-golden-ratio))
:config
(validate-setq
golden-ratio-extra-commands '(windmove-up
windmove-down
windmove-left
windmove-right
ace-window
ace-delete-window
ace-select-window
ace-swap-window
ace-maximize-window)
;; Exclude a couple of special modes from golden ratio, namely
;; Flycheck's error list, calc
golden-ratio-exclude-modes '(flycheck-error-list-mode
calc-mode
dired-mode
ediff-mode
)
golden-ratio-exclude-buffer-regexp
`(,(rx bos "*which-key*" eos)
,(rx bos "*NeoTree*" eos)))
:diminish (golden-ratio-mode . "ⓖ"))
(use-package ediff-wind ; Ediff window management
:defer t
:config
;; Prevent Ediff from spamming the frame
(validate-setq ediff-window-setup-function #'ediff-setup-windows-plain
ediff-split-window-function #'split-window-horizontally))
(use-package desktop ; Save buffers, windows and frames
:disabled t
:init (desktop-save-mode)
:config
;; Save desktops a minute after Emacs was idle.
(validate-setq desktop-auto-save-timeout 60)
;; Don't save Magit and Git related buffers
(dolist (mode '(magit-mode magit-log-mode))
(add-to-list 'desktop-modes-not-to-save mode))
(add-to-list 'desktop-files-not-to-save (rx bos "COMMIT_EDITMSG")))
(use-package writeroom-mode ; Distraction-free editing
:ensure t
:bind (("C-c t R" . writeroom-mode)))
(use-package popup ; Popup menus
;; We don't ensure this package, because we definitely don't want to have this
;; mess, but unfortunately it's a dependency of Ensime :(
:ensure nil
:defer t
:config
;; Bring Popup bindings in line with Company bindings, by getting rid of C-n/p
;; for navigation and introducing M-n/p
(define-key popup-menu-keymap "\C-n" nil)
(define-key popup-menu-keymap [down] nil)
(define-key popup-menu-keymap "\C-p" nil)
(define-key popup-menu-keymap [up] nil)
(define-key popup-menu-keymap (kbd "M-n") #'popup-next)
(define-key popup-menu-keymap (kbd "M-p") #'popup-previous))
;;; File handling
;; Keep backup and auto save files out of the way
(validate-setq
backup-directory-alist `((".*" . ,(locate-user-emacs-file ".backup")))
auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))
;; Delete files to trash
(validate-setq delete-by-moving-to-trash t)
(use-package files ; Core commands for files
:bind (("C-c f z" . revert-buffer)
("C-c f /" . revert-buffer))
:config
;; Use GNU ls for Emacs
(when-let (gnu-ls (and (eq system-type 'darwin) (executable-find "gls")))
(validate-setq insert-directory-program gnu-ls)))
(use-package ffap ; Find files at point
:defer t
;; Please stop pinging random hosts! See
;; https://github.com/technomancy/emacs-starter-kit/issues/39
:config (setq ffap-machine-p-known 'reject))
(use-package server ; The server of `emacsclient'
:if (not noninteractive)
:defer t
:init (server-mode)
:diminish (server-buffer-clients . " ⓒ"))
(use-package dired ; Edit directories
:defer t
:config
(validate-setq
dired-auto-revert-buffer t ; Revert on re-visiting
;; Better dired flags: `-l' is mandatory, `-a' shows all files, `-h' uses
;; human-readable sizes, and `-F' appends file-type classifiers to file names
;; (for better highlighting)
dired-listing-switches "-alhF"
dired-ls-F-marks-symlinks t ; -F marks links with @
;; Inhibit prompts for simple recursive operations
dired-recursive-copies 'always
;; Auto-copy to other Dired split window
dired-dwim-target t)
(when (or (memq system-type '(gnu gnu/linux))
(string= (file-name-nondirectory insert-directory-program) "gls"))
;; If we are on a GNU system or have GNU ls, add some more `ls' switches:
;; `--group-directories-first' lists directories before files, and `-v'
;; sorts numbers in file names naturally, i.e. "image1" goes before
;; "image02"
(validate-setq
dired-listing-switches
(concat dired-listing-switches " --group-directories-first -v"))))
(use-package dired-x ; Additional tools for Dired
:defer t
:bind (("C-c f j" . dired-jump)
("C-x C-j" . dired-jump))
:init
(add-hook 'dired-mode-hook #'dired-omit-mode)
:after dired
:config
(validate-setq dired-omit-verbose nil) ; Shut up, dired
(when (eq system-type 'darwin)
;; OS X bsdtar is mostly compatible with GNU Tar
(validate-setq dired-guess-shell-gnutar "tar"))
;; Diminish dired-omit-mode. We need this hack, because Dired Omit Mode has
;; a very peculiar way of registering its lighter explicitly in
;; `dired-omit-startup'. We can't just use `:diminish' because the lighter
;; isn't there yet after dired-omit-mode is loaded.
(add-function :after (symbol-function 'dired-omit-startup)
(lambda () (diminish 'dired-omit-mode " ⓞ"))
'((name . dired-omit-mode-diminish))))
(use-package neotree
:ensure t
:bind (("C-c f t" . neotree-toggle))
:config (validate-setq neo-window-width 32
neo-create-file-auto-open t
neo-banner-message nil
neo-show-updir-line nil
neo-mode-line-type 'neotree
neo-smart-open t
neo-dont-be-alone t
neo-persist-show nil
neo-show-hidden-files t
neo-auto-indent-point t))
(use-package ignoramus ; Ignore uninteresting files everywhere
:ensure t
:config
;; Ignore some additional directories and file extensions
(dolist (name '("company-statistics-cache.el"
".cask"
".vagrant"
".ensime_cache" ".ensime"
".stack-work"))
;; Ignore some additional directories
(add-to-list 'ignoramus-file-basename-exact-names name))
(dolist (ext '(".fls" ".out" ; LaTeX
))
(add-to-list 'ignoramus-file-endings ext))
(ignoramus-setup))
(use-package hardhat ; Protect user-writable files
:ensure t
:init (global-hardhat-mode)
:config (validate-setq hardhat-mode-lighter " Ⓗ"))
(use-package bookmark ; Bookmarks for Emacs buffers
:bind (("C-c f b" . list-bookmarks))
;; Save bookmarks immediately after a bookmark was added
:config (validate-setq bookmark-save-flag 1))
(use-package recentf ; Save recently visited files
:init (recentf-mode)
:config
(validate-setq
recentf-max-saved-items 200
recentf-max-menu-items 15
;; Cleanup recent files only when Emacs is idle, but not when the mode
;; is enabled, because that unnecessarily slows down Emacs. My Emacs
;; idles often enough to have the recent files list clean up regularly
recentf-auto-cleanup 300
recentf-exclude (list "/\\.git/.*\\'" ; Git contents
"/elpa/.*\\'" ; Package files
"/itsalltext/" ; It's all text temp files
;; And all other kinds of boring files
#'ignoramus-boring-p)))
(use-package saveplace ; Save point position in files
:init (save-place-mode 1))
(validate-setq view-read-only t) ; View read-only files
(use-package autorevert ; Auto-revert buffers of changed files
:init (global-auto-revert-mode)
:config
(validate-setq auto-revert-verbose nil ; Shut up, please!
;; Revert Dired buffers, too
global-auto-revert-non-file-buffers t)
(when (eq system-type 'darwin)
;; File notifications aren't supported on OS X
(validate-setq auto-revert-use-notify nil))
:diminish (auto-revert-mode . " Ⓐ"))
(use-package image-file ; Visit images as images
:init (auto-image-file-mode))
(use-package launch ; Open files in external programs
:ensure t
:defer t)
(use-package sudo-edit ; Edit files as root, through Tramp
:ensure t
:defer t
:bind (("C-c f s" . sudo-edit)))
(use-package reveal-in-osx-finder ; Reveal current buffer in finder
:ensure t
;; Bind analogous to `dired-jump' at C-c f j
:bind (("C-c f J" . reveal-in-osx-finder)))
(use-package lunaryorn-files ; Personal file tools
:load-path "lisp/"
:commands (lunaryorn-recompile-packages)
:bind (("C-c f D" . lunaryorn-delete-file-and-buffer)
("C-c f i" . lunaryorn-open-in-intellij)
("C-c f o" . lunaryorn-launch-dwim)
("C-c f R" . lunaryorn-rename-file-and-buffer)
("C-c f w" . lunaryorn-copy-filename-as-kill)
("C-c f u" . lunaryorn-find-user-init-file-other-window)
("C-c f ." . lunaryorn-browse-feature-url)))
;; Additional bindings for built-ins
(bind-key "C-c f v d" #'add-dir-local-variable)
(bind-key "C-c f v l" #'add-file-local-variable)
(bind-key "C-c f v p" #'add-file-local-variable-prop-line)
;;; Navigation and scrolling
(validate-setq
scroll-conservatively 1000 ; Never recenter the screen while scrolling
scroll-error-top-bottom t ; Move to beg/end of buffer before
; signalling an error
;; These settings make trackpad scrolling on OS X much more predictable
;; and smooth
mouse-wheel-progressive-speed nil
mouse-wheel-scroll-amount '(1))
(use-package page ; Page navigation
:bind (("C-x ]" . lunaryorn-pages/forward-page)
("C-x [" . lunaryorn-pages/backward-page))
:init
(defhydra lunaryorn-pages ()
"Pages"
("[" backward-page "backward")
("]" forward-page "forward")))
(use-package ivy-pages ; Jump to pages with ivy
:ensure t
:defer t
:bind (("C-c j p" . ivy-pages)))
(use-package avy-jump ; Jump to characters in buffers
:ensure avy
:defer t
:bind (("C-c j w" . avy-goto-word-1)
("C-c j l" . avy-goto-line)
("C-c j b" . avy-pop-mark)
("C-c j j" . avy-goto-char-2)))
(use-package ace-link ; Fast link jumping
:ensure t
:defer t
:bind (:map Info-mode-map ("C-c m l" . ace-link-info)
:map help-mode-map ("C-c m l" . ace-link-help)))