-
Notifications
You must be signed in to change notification settings - Fork 16
/
init.el
1941 lines (1612 loc) · 65.3 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-2015 Sebastian Wiesner <[email protected]>
;;
;; Author: Sebastian Wiesner <[email protected]>
;; 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:
;;; 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)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize)
;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
;;; Requires
(require 'subr-x)
(require 'rx)
(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)
;; Warn if the current build is more than a week old
(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!")))))
;;; Environment fixup
(use-package exec-path-from-shell
:ensure t
:if (and (eq system-type 'darwin) (display-graphic-p))
:init
(progn
(when (string-match-p "/zsh$" (getenv "SHELL"))
;; Use a non-interactive shell. We use a login shell, even though we have
;; our paths setup in .zshenv. However, OS X adds global settings to the
;; login profile. Notably, this affects /usr/texbin from MacTeX
(setq exec-path-from-shell-arguments '("-l")))
(dolist (var '("EMAIL" "PYTHONPATH" "INFOPATH"))
(add-to-list 'exec-path-from-shell-variables var))
(exec-path-from-shell-initialize)
(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'.
(with-eval-after-load 'info
(dolist (dir (parse-colon-path (getenv "INFOPATH")))
(when dir
(add-to-list 'Info-directory-list dir))))))
;;; Customization interface
(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
(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))
;;; OS X support
(use-package ns-win ; OS X window support
:defer t
:if (eq system-type 'darwin)
:config
(setq ns-pop-up-frames nil ; Don't pop up new frames from the
; workspace
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
mac-right-option-modifier 'none ; Keep right option for accented input
;; Just in case we ever need these keys
mac-function-modifier 'hyper))
(use-package lunaryorn-osx ; Personal OS X tools
:if (eq system-type 'darwin)
:load-path "lisp/"
:defines (lunaryorn-darwin-trash-tool)
:init
(if (executable-find lunaryorn-darwin-trash-tool)
(defalias 'system-move-file-to-trash 'lunaryorn-darwin-move-file-to-trash)
(warn "Trash support not available!
Install Trash from https://github.com/ali-rantakari/trash!
Homebrew: brew install trash")))
;;; 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)
(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)
(use-package lunaryorn-scratch ; My logo in the scratch buffer
:commands (lunaryorn-insert-logo
lunaryorn-insert-logo-into-scratch)
:init
(add-hook 'after-init-hook #'lunaryorn-insert-logo-into-scratch))
(use-package dynamic-fonts ; Select best available font
:ensure t
:init
(progn
(setq dynamic-fonts-preferred-monospace-fonts
'(
;; Best fonts
"Source Code Pro" ; https://github.com/adobe-fonts/source-code-pro
"Anonymous Pro" ; http://www.marksimonson.com/fonts/view/anonymous-pro
;; Consolas and its free alternative. Ok, but not my preference
"Inconsolata"
"Consolas"
;; Also still kind of ok
"Fira Mono"
;; System fonts, as last resort
"Menlo"
"DejaVu Sans Mono"
"Bitstream Vera Mono"
"Courier New")
dynamic-fonts-preferred-monospace-point-size (pcase system-type
(`darwin 13)
(_ 10))
dynamic-fonts-preferred-proportional-fonts
'(
;; Best, from
;; https://www.mozilla.org/en-US/styleguide/products/firefox-os/typeface/
"Fira Sans"
;; System fonts, as last resort
"Helvetica"
"Segoe UI"
"DejaVu Sans"
"Bitstream Vera"
"Tahoma"
"Verdana"
"Arial Unicode MS"
"Arial")
dynamic-fonts-preferred-proportional-point-size (pcase system-type
(`darwin 13)
(_ 10)))
(dynamic-fonts-setup)))
(use-package unicode-fonts ; Map Unicode blocks to fonts
:ensure t
:init (unicode-fonts-setup))
(use-package solarized ; My colour theme
:ensure solarized-theme
:defer t
:init (load-theme 'solarized-light 'no-confirm)
:config t
;; Disable variable pitch fonts in Solarized theme
(setq solarized-use-variable-pitch nil
;; Don't add too much colours to the fringe
solarized-emphasize-indicators nil
;; 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))
(bind-key "C-c t v" #'variable-pitch-mode)
;;; The mode line
(setq-default header-line-format
'(which-func-mode ("" which-func-format " "))
mode-line-format
'("%e" mode-line-front-space
;; Standard info about the current buffer
mode-line-mule-info
mode-line-client
mode-line-modified
mode-line-remote
mode-line-frame-identification
mode-line-buffer-identification " " mode-line-position
;; Some specific information about the current buffer:
;; - Paredit
;; - Dired Omit Mode
(paredit-mode (:propertize " ()" face bold))
;; A little complicated, pending
;; https://github.com/rolandwalker/ignoramus/pull/3
(dired-omit-mode (:eval (when (derived-mode-p 'dired-mode)
" ●")))
;; Warn if whitespace isn't highlighted or cleaned in this
;; buffer.
(:eval (unless buffer-read-only
(cond
((not (bound-and-true-p whitespace-mode))
(propertize " SPACE" 'face '(bold error)))
((not (bound-and-true-p whitespace-cleanup-mode))
(propertize " WSC" 'face 'warning)))))
(projectile-mode projectile-mode-line)
(vc-mode vc-mode)
(flycheck-mode flycheck-mode-line) ; Flycheck status
(anzu-mode (:eval ; isearch pos/matches
(when (> anzu--total-matched 0)
(concat " " (anzu--update-mode-line)))))
(multiple-cursors-mode mc/mode-line) ; Number of cursors
;; And the modes, which we don't really care for anyway
" " mode-line-misc-info mode-line-modes mode-line-end-spaces)
mode-line-remote
'(:eval
(when-let (host (file-remote-p default-directory 'host))
(propertize (concat "@" host) 'face
'(italic warning))))
;; Remove which func from the mode line, since we have it in the
;; header line
mode-line-misc-info
(assq-delete-all 'which-func-mode mode-line-misc-info))
;; Standard stuff
(line-number-mode)
(column-number-mode)
(use-package fancy-battery ; Fancy battery info for mode line
:ensure t
:defer t
:idle (fancy-battery-mode)
:idle-priority 10)
(use-package anzu ; Position/matches count for isearch
:ensure t
:init (global-anzu-mode)
:config (setq anzu-cons-mode-line-p nil)
:diminish anzu-mode)
(use-package which-func ; Current function name in header line
:defer t
:idle (which-function-mode)
:idle-priority 1
:config
(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"))))
;;; The minibuffer
(setq history-length 1000) ; Store more history
(use-package savehist ; Save minibuffer history
:init (savehist-mode t)
:config (setq savehist-save-minibuffer-history t
savehist-autosave-interval 180))
(use-package ido ; Better minibuffer completion
:init (progn
(ido-mode)
(ido-everywhere))
:config
(setq ido-enable-flex-matching t ; Match characters if string doesn't
; match
ido-create-new-buffer 'always ; Create a new buffer if nothing matches
ido-use-filename-at-point 'guess
;; Visit buffers and files in the selected window
ido-default-file-method 'selected-window
ido-default-buffer-method 'selected-window
ido-use-faces nil)) ; Prefer flx ido faces
(use-package ido-ubiquitous ; IDO everywhere, really!
:ensure t
:init (ido-ubiquitous-mode))
(use-package flx-ido ; Flex matching for IDO
:ensure t
:init (flx-ido-mode))
(use-package ido-vertical-mode ; Vertical interface for IDO
:ensure t
:init (ido-vertical-mode))
(use-package smex ; Better M-x
:ensure t
:bind (([remap execute-extended-command] . smex)
("M-X" . smex-major-mode-commands)))
;;; Buffer, Windows and Frames
(setq frame-resize-pixelwise t ; Resize by pixels
frame-title-format
'(:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name)) "%b")))
(use-package frame
:bind (("C-c T 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 lunaryorn-buffers ; Personal buffer tools
:load-path "lisp/"
:commands (lunaryorn-force-save-some-buffers
lunaryorn-do-not-kill-important-buffers)
:init
(progn
(add-hook 'kill-buffer-query-functions
#'lunaryorn-do-not-kill-important-buffers)
;; Autosave buffers when focus is lost, see
;; http://emacsredux.com/blog/2014/03/22/a-peek-at-emacs-24-dot-4-focus-hooks/
(add-hook 'focus-out-hook #'lunaryorn-force-save-some-buffers)))
(use-package uniquify ; Make buffer names unique
:config (setq uniquify-buffer-name-style 'forward))
(use-package ibuffer ; Better buffer list
:bind (([remap list-buffers] . ibuffer))
;; Show VC Status in ibuffer
:config (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
:defer t)
(use-package windmove ; Move between windows with Shift+Arrow
:bind (((kbd "S-<left>") . windmove-left)
((kbd "S-<right>") . windmove-right)
((kbd "S-<up>") . windmove-up)
((kbd "S-<down>") . windmove-down)))
(use-package winner ; Undo and redo window configurations
:init (winner-mode))
(use-package ediff-wind
:defer t
:config
;; Prevent Ediff from spamming the frame
(setq ediff-window-setup-function #'ediff-setup-windows-plain
ediff-split-window-function #'split-window-horizontally))
(use-package desktop ; Save buffers, windows and frames
:init (desktop-save-mode)
:config (progn
;; Don't autosave desktops, it's too expensive. Desktops aren't
;; that precious, and Emacs will save the desktop on exit anyway.
(setq desktop-auto-save-timeout nil)
(dolist (mode '(magit-mode git-commit-mode))
(add-to-list 'desktop-modes-not-to-save mode))))
(use-package writeroom-mode ; Distraction-free editing
:ensure t
:bind (("C-c T R" . writeroom-mode)))
;;; File handling
;; Keep backup and auto save files out of the way
(setq backup-directory-alist `((".*" . ,(locate-user-emacs-file ".backup")))
auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))
;; Delete files to trash
(setq delete-by-moving-to-trash
(or (not (eq system-type 'darwin)) ; Trash is well supported on other
; systems
(fboundp 'system-move-file-to-trash)))
(use-package files
:bind (("C-c f u" . revert-buffer))
:config
;; Use GNU ls for Emacs
(when-let (gnu-ls (and (eq system-type 'darwin) (executable-find "gls")))
(setq insert-directory-program gnu-ls)))
(use-package tramp ; Access remote files
:defer t
:config
;; Store auto-save files locally
(setq tramp-auto-save-directory (locate-user-emacs-file "tramp-auto-save")))
(use-package dired ; Edit directories
:defer t
:config
(progn
(require 'dired-x)
(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)
(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"
(setq dired-listing-switches
(concat dired-listing-switches " --group-directories-first -v")))))
(use-package dired-x ; Additional tools for Dired
:defer t
:config
(progn
(setq dired-omit-verbose nil) ; Shut up, dired
(when (eq system-type 'darwin)
;; OS X bsdtar is mostly compatible with GNU Tar
(setq dired-guess-shell-gnutar "tar")))
:diminish ((dired-omit-mode . " ●")))
(use-package copyright ; Deal with copyright notices
:defer t
:bind (("C-c u C" . copyright-update))
;; Update copyright when visiting files
:init (add-hook 'find-file-hook #'copyright-update)
;; Use ranges to denote consecutive years
:config (setq copyright-year-ranges t
copyright-names-regexp (regexp-quote user-full-name)))
(use-package ignoramus ; Ignore uninteresting files everywhere
:ensure t
:defer t
:idle (ignoramus-setup))
(use-package hardhat ; Protect user-writable files
:ensure t
:defer t
:idle (global-hardhat-mode))
(use-package bookmark ; Bookmarks for Emacs buffers
:bind (("C-c l b" . list-bookmarks))
;; Save bookmarks immediately after a bookmark was added
:config (setq bookmark-save-flag 1))
(use-package recentf ; Save recently visited files
:defer t
:idle (recentf-mode)
:config
(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
:config (setq-default save-place t))
(setq view-read-only t) ; View read-only files
(use-package autorevert ; Auto-revert buffers of changed files
:init (global-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
:idle (global-launch-mode))
(use-package ido-load-library ; Load libraries with IDO
:ensure t
:bind ("C-c f l" . ido-load-library-find))
(use-package lunaryorn-files ; Personal file tools
:load-path "lisp/"
:bind (("C-c f D" . lunaryorn-delete-file-and-buffer)
("C-c f i" . lunaryorn-find-user-init-file-other-window)
("C-c f o" . lunaryorn-launch-dwim)
("C-c f r" . lunaryorn-ido-find-recentf)
("C-c f R" . lunaryorn-rename-file-and-buffer)
("C-c f w" . lunaryorn-copy-filename-as-kill)))
;;; 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)
;;; Basic editing
;; Disable tabs, but given them proper width
(setq-default indent-tabs-mode nil
tab-width 8)
;; Make Tab complete if the line is indented
(setq tab-always-indent 'complete)
(use-package electric ; Electric code layout
:init (electric-layout-mode))
(use-package elec-pair ; Electric pairs
:init (electric-pair-mode))
;; Indicate empty lines at the end of a buffer in the fringe, but require a
;; final new line
(setq indicate-empty-lines t
require-final-newline t)
(setq kill-ring-max 200 ; More killed items
;; Save the contents of the clipboard to kill ring before killing
save-interprogram-paste-before-kill t)
;; Configure a reasonable fill column, indicate it in the buffer and enable
;; automatic filling
(setq-default fill-column 80)
(add-hook 'text-mode-hook #'auto-fill-mode)
(use-package lunaryorn-simple ; Personal editing helpers
:load-path "lisp/"
:bind (([remap kill-whole-line] . lunaryorn-smart-kill-whole-line)
([remap move-beginning-of-line] . lunaryorn-back-to-indentation-or-beginning-of-line)
("C-<backspace>" . lunaryorn-smart-backward-kill-line)
("C-S-j" . lunaryorn-smart-open-line)
;; Additional utilities
("C-c u d" . lunaryorn-insert-current-date))
:commands (lunaryorn-auto-fill-comments-mode)
;; Auto-fill comments in programming modes
:init (add-hook 'prog-mode-hook #'lunaryorn-auto-fill-comments-mode))
(use-package delsel ; Delete the selection instead of insert
:defer t
:init (delete-selection-mode))
(use-package whitespace-cleanup-mode ; Cleanup whitespace in buffers
:ensure t
:bind (("C-c T W" . whitespace-cleanup-mode))
:init (dolist (hook '(prog-mode-hook text-mode-hook conf-mode-hook))
(add-hook hook #'whitespace-cleanup-mode))
:diminish whitespace-cleanup-mode)
(use-package subword ; Subword/superword editing
:defer t
:diminish subword-mode)
(use-package adaptive-wrap ; Choose wrap prefix automatically
:ensure t
:defer t
:init (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode))
(use-package visual-fill-column
:ensure t
:defer t
:init (add-hook 'visual-line-mode-hook #'visual-fill-column-mode)
;; Keep the fringe
:config (setq visual-fill-column-disable-fringe nil))
(use-package visual-regexp ; Regexp replace with in-buffer display
:ensure t
:bind (("C-c r" . vr/query-replace)
("C-c R" . vr/replace)))
(use-package browse-kill-ring ; Browse kill ring interactively
:ensure t
:bind (("C-c y" . browse-kill-ring)))
(use-package zop-to-char
:ensure t
:bind (("M-z" . zop-to-char)
("M-Z" . zop-up-to-char)))
(use-package easy-kill ; Easy killing and marking on C-w
:ensure t
:bind (([remap kill-ring-save] . easy-kill)
([remap mark-sexp] . easy-mark)))
(use-package align ; Align text in buffers
:bind (("C-c A a" . align)
("C-c A c" . align-current)
("C-c A r" . align-regexp)))
(use-package multiple-cursors ; Edit text with multiple cursors
:ensure t
:bind (("C-c m e" . mc/mark-more-like-this-extended)
("C-c m h" . mc/mark-all-like-this-dwim)
("C-c m l" . mc/edit-lines)
("C-c m n" . mc/mark-next-like-this)
("C-c m p" . mc/mark-previous-like-this)
("C-c m r" . vr/mc-mark)
("C-c m C-a" . mc/edit-beginnings-of-lines)
("C-c m C-e" . mc/edit-ends-of-lines)
("C-c m C-s" . mc/mark-all-in-region))
:config
(setq mc/mode-line
;; Simplify the MC mode line indicator
'(:propertize (:eval (concat " " (number-to-string (mc/num-cursors))))
face font-lock-warning-face)))
(use-package expand-region ; Expand region by semantic units
:ensure t
:bind (("C-=" . er/expand-region)))
(use-package undo-tree ; Branching undo
:ensure t
:init (global-undo-tree-mode)
:diminish undo-tree-mode)
(use-package nlinum ; Line numbers in display margin
:ensure t
:bind (("C-c T l" . nlinum-mode)))
;; Give us narrowing back!
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-defun 'disabled nil)
;; Same for region casing
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(use-package server ; The server of `emacsclient'
:defer t
:idle (server-start))
;; Additional keybindings
(bind-key [remap just-one-space] #'cycle-spacing)
(bind-key "M-Z" #'zap-up-to-char)
;;; Navigation and scrolling
(setq scroll-margin 0 ; Drag the point along while scrolling
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 ace-jump-mode ; Jump to characters in buffers
:ensure t
:bind (("C-c SPC" . ace-jump-mode)
("C-c j" . ace-jump-mode)
("C-c J" . ace-jump-mode-pop-mark))
:config
;; Sync marks with Emacs built-in commands
(ace-jump-mode-enable-mark-sync))
(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 outline ; Navigate outlines in buffers
:defer t
:init (dolist (hook '(text-mode-hook prog-mode-hook))
(add-hook hook #'outline-minor-mode))
:diminish outline-minor-mode)
(use-package imenu-anywhere ; IDO-based imenu across open buffers
:ensure t
:bind (("C-c i" . imenu-anywhere)))
;;; Search
(use-package isearch ; Search buffers
:bind (("C-c s s" . isearch-forward-symbol-at-point)))
(use-package grep
:defer t
:config
(progn
(when-let (gnu-find (and (eq system-type 'darwin)
(executable-find "gfind")))
(setq find-program gnu-find))
(when-let (gnu-xargs (and (eq system-type 'darwin)
(executable-find "gxargs")))
(setq xargs-program gnu-xargs))))
(use-package locate ; Search files on the system
:defer t
:config
;; Use mdfind as locate substitute on OS X, to utilize the Spotlight database
(when-let (mdfind (and (eq system-type 'darwin) (executable-find "mdfind")))
(setq locate-command mdfind)))
(use-package ag ; Search code in files/projects
:ensure t
:bind (("C-c a a" . ag-regexp)
("C-c a A" . ag)
("C-c a d" . ag-dired-regexp)
("C-c a D" . ag-dired)
("C-c a f" . ag-files)
("C-c a k" . ag-kill-other-buffers)
("C-c a K" . ag-kill-buffers))
:config
(setq ag-reuse-buffers t ; Don't spam buffer list with ag buffers
ag-highlight-search t ; A little fanciness
;; Use Projectile to find the project root
ag-project-root-function (lambda (d) (let ((default-directory d))
(projectile-project-root)))))
(use-package wgrep ; Edit grep/occur/ag results in-place
:ensure t
:defer t)
(use-package wgrep-ag ; Wgrep for ag
:ensure t
:defer t)
;;; Highlights
(use-package whitespace ; Highlight bad whitespace
:bind (("C-c T w" . whitespace-mode))
:init
(dolist (hook '(prog-mode-hook text-mode-hook conf-mode-hook))
(add-hook hook #'whitespace-mode))
:config
;; Highlight tabs, empty lines at beg/end, trailing whitespaces and overlong
;; portions of lines via faces. Also indicate tabs via characters
(setq whitespace-style '(face indentation space-after-tab space-before-tab
tab-mark empty trailing lines-tail)
whitespace-line-column nil) ; Use `fill-column' for overlong lines
:diminish whitespace-mode)
;; A function to disable highlighting of long lines in modes
(defun lunaryorn-whitespace-style-no-long-lines ()
"Configure `whitespace-mode' for Org.
Disable the highlighting of overlong lines."
(setq-local whitespace-style (-difference whitespace-style
'(lines lines-tail)))
(when whitespace-mode
(whitespace-mode -1)
(whitespace-mode 1)))
(use-package hl-line ; Highlight the current line
:init (global-hl-line-mode 1))
(use-package paren ; Highlight paired delimiters
:init (show-paren-mode)
:config (setq show-paren-when-point-inside-paren t
show-paren-when-point-in-periphery t))
(use-package rainbow-delimiters ; Highlight delimiters by depth
:ensure t
:defer t
:init (dolist (hook '(text-mode-hook prog-mode-hook))
(add-hook hook #'rainbow-delimiters-mode)))
(use-package hi-lock ; Custom regexp highlights
:init (global-hi-lock-mode))
;;; Skeletons, completion and expansion
;; In `completion-at-point', do not pop up silly completion buffers for less
;; than five candidates. Cycle instead.
(setq completion-cycle-threshold 5)
(use-package hippie-exp ; Powerful expansion and completion
:bind (([remap dabbrev-expand] . hippie-expand))
:config
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-complete-lisp-symbol-partially
try-complete-lisp-symbol
lunaryorn-try-complete-lisp-symbol-without-namespace)))
(use-package lunaryorn-hippie-exp ; Custom expansion functions
:load-path "lisp/"
:commands (lunaryorn-try-complete-lisp-symbol-without-namespace))
(use-package company ; Graphical (auto-)completion
:ensure t
:defer t
:idle (global-company-mode)
:config
(progn
;; Use Company for completion
(bind-key [remap completion-at-point] #'company-complete company-mode-map)
(setq company-tooltip-align-annotations t
;; Easy navigation to candidates with M-<n>
company-show-numbers t))
:diminish company-mode)
(use-package company-quickhelp ; Documentation popups for Company
:ensure t
:defer t
:init (add-hook 'global-company-mode-hook #'company-quickhelp-mode))
(use-package company-math ; Completion for Math symbols
:ensure t
:defer t
:init
;; Add backend for math characters
(with-eval-after-load 'company
(add-to-list 'company-backends 'company-math-symbols-unicode)
(add-to-list 'company-backends 'company-math-symbols-latex)))
;;; Spelling and syntax checking
(use-package ispell ; Spell checking
:defer t
:config
(progn
(setq ispell-program-name (if (eq system-type 'darwin)
(executable-find "aspell")
(executable-find "hunspell"))
ispell-dictionary "en_GB" ; Default dictionnary
ispell-silently-savep t ; Don't ask when saving the private dict
;; Increase the height of the choices window to take our header line
;; into account.
ispell-choices-win-default-height 5)
(unless ispell-program-name
(warn "No spell checker available. Install Hunspell or ASpell for OS X."))))
(use-package flyspell ; On-the-fly spell checking
:bind (("C-c T s" . flyspell-mode))
:init
(progn
(dolist (hook '(text-mode-hook message-mode-hook))
(add-hook hook 'turn-on-flyspell))
(add-hook 'prog-mode-hook 'flyspell-prog-mode))
:config
(progn
(setq flyspell-use-meta-tab nil
;; Make Flyspell less chatty
flyspell-issue-welcome-flag nil
flyspell-issue-message-flag nil)
;; Free C-M-i for completion
(define-key flyspell-mode-map "\M-\t" nil))
:diminish flyspell-mode)
(use-package flycheck ; On-the-fly syntax checking
:ensure t
:bind (("C-c l e" . list-flycheck-errors)
("C-c T f" . flycheck-mode))
:init (global-flycheck-mode)
:config
(progn
(setq flycheck-completion-system 'ido)
;; Use italic face for checker name
(set-face-attribute 'flycheck-error-list-checker-name nil :inherit 'italic))
:diminish flycheck-mode)
(use-package flycheck-pos-tip ; Show Flycheck messages in popups
:ensure t
:defer t
:init
(setq flycheck-display-errors-function #'flycheck-pos-tip-error-messages))
(use-package lunaryorn-flycheck ; Personal Flycheck helpers
:defer t
:commands (lunaryorn-discard-undesired-html-tidy-error
lunaryorn-flycheck-mode-line-status)
:init (with-eval-after-load 'flycheck
;; Don't highlight undesired errors from html tidy
(add-hook 'flycheck-process-error-functions
#'lunaryorn-discard-undesired-html-tidy-error)
(setq flycheck-mode-line
'(:eval (lunaryorn-flycheck-mode-line-status)))))
;;; Text editing
(use-package tildify
:bind (("C-c u t" . tildify-region))
:init
(progn
(dolist (hook '(markdown-mode-hook
latex-mode-hook
rst-mode-hook))
(add-hook hook #'tildify-mode))
;; Use the right space for LaTeX
(add-hook 'latex-mode-hook
(lambda () (setq-local tildify-space-string "~")))))
(use-package typo
:ensure t