-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
965 lines (764 loc) · 32.1 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
;;; init.el --- Where all the magic begins
;;
;; Adapted from the Emacs Starter Kit
;;
;; This is the first thing to get loaded.
;;
;; "Emacs outshines all other editing software in approximately the
;; same way that the noonday sun does the stars. It is not just bigger
;; and brighter; it simply makes everything else vanish."
;; -Neal Stephenson, "In the Beginning was the Command Line"
;; Turn off mouse interface early in startup to avoid momentary display
;; You really don't need these; trust me.
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;; Load path etc.
(setq dotfiles-dir (file-name-directory
(or (buffer-file-name) load-file-name)))
;; Load up ELPA, the package manager
(add-to-list 'load-path (concat dotfiles-dir "/lisp"))
(setq package-user-dir (concat dotfiles-dir "elpa"))
(setq custom-file (concat dotfiles-dir "custom.el"))
(load custom-file)
(require 'package)
(dolist (source '(("melpa" . "https://melpa.org/packages/")))
(add-to-list 'package-archives source t))
(package-initialize)
(require 'cl-lib)
(defvar my-packages
(list 'idle-highlight-mode 'rg 'nord-theme 'yaml-mode
'ruby-mode 'inf-ruby 'ruby-tools 'rvm 'find-file-in-project 'gist
'rust-mode 'cargo 'pythonic 'abl-mode 'dockerfile-mode
'yasnippet 'redis 'terraform-mode 'hcl-mode
'web-mode 'web-mode-edit-element 'css-mode 'html-mode
'ruby-electric 'javadoc-lookup 'java-snippets
'markdown-mode 'markdown-mode+ 'scpaste
'elpy 'cider 'py-autopep8 'flycheck 'org-journal)
"Libraries that should be installed by default.")
(defun starter-kit-elpa-install ()
"Install all starter-kit packages that aren't installed."
(interactive)
(dolist (package my-packages)
(unless (or (member package package-activated-list)
(functionp package))
(message "Installing %s" (symbol-name package))
(package-install package))))
(defun esk-online? ()
"See if we're online.
Windows does not have the network-interface-list function, so we
just have to assume it's online."
(if (and (functionp 'network-interface-list)
(network-interface-list))
(cl-some (lambda (iface) (unless (equal "lo" (car iface))
(member 'up (car (last (network-interface-info
(car iface)))))))
(network-interface-list))
t))
;; On your first run, pull in all the base packages.
(when (esk-online?)
(unless package-archive-contents (package-refresh-contents))
(starter-kit-elpa-install))
;; Workaround for an ELPA bug that people are reporting but I've been
;; unable to reproduce:
(autoload 'paredit-mode "paredit" "" t)
;; Workaround for bug in the ELPA package for yaml-mode
(autoload 'yaml-mode "yaml-mode" "" t)
;; These should be loaded on startup rather than autoloaded on demand
;; since they are likely to be used in every session
(require 'saveplace)
(require 'ffap)
(require 'uniquify)
(require 'ansi-color)
(require 'recentf)
;; Save a list of recent files visited.
(recentf-mode 1)
;; Load up starter kit customizations
;;; starter-kit-defuns.el --- Define some custom functions
;;
;; Part of the Emacs Starter Kit
(require 'thingatpt)
(require 'imenu)
;; Network
(defun view-url ()
"Open a new buffer containing the contents of URL."
(interactive)
(let* ((default (thing-at-point-url-at-point))
(url (read-from-minibuffer "URL: " default)))
(switch-to-buffer (url-retrieve-synchronously url))
(rename-buffer url t)
;; TODO: switch to nxml/nxhtml mode
(cond ((search-forward "<?xml" nil t) (xml-mode))
((search-forward "<html" nil t) (html-mode)))))
;; We have a number of turn-on-* functions since it's advised that lambda
;; functions not go in hooks. Repeatedly evaling an add-to-list with a
;; hook value will repeatedly add it since there's no way to ensure
;; that a lambda doesn't already exist in the list.
(defun local-column-number-mode ()
(make-local-variable 'column-number-mode)
(column-number-mode t))
(defun local-comment-auto-fill ()
(set (make-local-variable 'comment-auto-fill-only-comments) t)
(auto-fill-mode t))
(defun turn-on-hl-line-mode ()
(when (> (display-color-cells) 8) (hl-line-mode t)))
(defun turn-on-save-place-mode ()
(setq save-place t))
(defun turn-on-whitespace ()
(whitespace-mode t))
(defun turn-on-paredit ()
(paredit-mode t))
(defun turn-off-tool-bar ()
(tool-bar-mode -1))
(defun turn-on-idle-highlight ()
(idle-highlight-mode t))
(defun add-watchwords ()
(font-lock-add-keywords
nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
1 font-lock-warning-face t))))
(add-hook 'coding-hook 'local-column-number-mode)
(add-hook 'coding-hook 'local-comment-auto-fill)
(add-hook 'coding-hook 'turn-on-hl-line-mode)
(add-hook 'coding-hook 'turn-on-save-place-mode)
(add-hook 'coding-hook 'pretty-lambdas)
(add-hook 'coding-hook 'add-watchwords)
(add-hook 'coding-hook 'turn-on-idle-highlight)
(defun run-coding-hook ()
"Enable things that are convenient across all coding buffers."
(run-hooks 'coding-hook))
(defun untabify-buffer ()
(interactive)
(untabify (point-min) (point-max)))
(defun indent-buffer ()
(interactive)
(indent-region (point-min) (point-max)))
(defun cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer."
(interactive)
(indent-buffer)
(untabify-buffer)
(delete-trailing-whitespace))
(defun recentf-ido-find-file ()
"Find a recent file using ido."
(interactive)
(let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
(when file
(find-file file))))
;; Cosmetic
(defun pretty-lambdas ()
(font-lock-add-keywords
nil `(("(?\\(lambda\\>\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(make-char 'greek-iso8859-7 107))
nil))))))
;; Other
(defun eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(condition-case nil
(prin1 (eval (read (current-kill 0)))
(current-buffer))
(error (message "Invalid expression")
(insert (current-kill 0)))))
(defun recompile-init ()
"Byte-compile all your dotfiles again."
(interactive)
(byte-recompile-directory dotfiles-dir 0)
;; TODO: remove elpa-to-submit once everything's submitted.
(byte-recompile-directory (concat dotfiles-dir "elpa-to-submit/") 0))
(defun sudo-edit (&optional arg)
(interactive "p")
(if (or arg (not buffer-file-name))
(find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
(defun lorem ()
"Insert a lorem ipsum."
(interactive)
(insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
"ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
"aliquip ex ea commodo consequat. Duis aute irure dolor in "
"reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
"culpa qui officia deserunt mollit anim id est laborum."))
(defun switch-or-start (function buffer)
"If the buffer is current, bury it, otherwise invoke the function."
(if (equal (buffer-name (current-buffer)) buffer)
(bury-buffer)
(if (get-buffer buffer)
(switch-to-buffer buffer)
(funcall function))))
(defun insert-date ()
"Insert a time-stamp according to locale's date and time format."
(interactive)
(insert (format-time-string "%c" (current-time))))
(defun pairing-bot ()
"If you can't pair program with a human, use this instead."
(interactive)
(message (if (y-or-n-p "Do you have a test for that? ") "Good." "Bad!")))
(defun esk-paredit-nonlisp ()
"Turn on paredit mode for non-lisps."
(set (make-local-variable 'paredit-space-delimiter-chars)
(list ?\"))
(paredit-mode 1))
(defun esk-space-for-delimiter? (endp delimiter)
(not (member major-mode '(ruby-mode espresso-mode js-mode js2-mode))))
(eval-after-load 'paredit
'(add-to-list 'paredit-space-for-delimiter-predicates
'esk-space-for-delimiter?))
(defun message-point ()
(interactive)
(message "%s" (point)))
(defun esk-disapproval ()
(interactive)
(insert "ಠ_ಠ"))
(defun esk-agent-path ()
(if (eq system-type 'darwin)
"*launch*/Listeners"
"*ssh*/agent\.*"))
(defun esk-find-agent ()
(let* ((path-clause (format "-path \"%s\"" (esk-agent-path)))
(find-command (format "$(find -L /tmp -uid $UID %s -type s 2> /dev/null)"
path-clause)))
(first (split-string
(shell-command-to-string
(format "/bin/ls -t1 %s | head -1" find-command))))))
(defun fix-agent ()
(interactive)
(let ((agent (esk-find-agent)))
(setenv "SSH_AUTH_SOCK" agent)
(message agent)))
(defun toggle-fullscreen ()
(interactive)
;; TODO: this only works for X. patches welcome for other OSes.
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)))
;; A monkeypatch to cause annotate to ignore whitespace
(defun vc-git-annotate-command (file buf &optional rev)
(let ((name (file-relative-name file)))
(vc-git-command buf 0 name "blame" "-w" rev)))
;;; starter-kit-defuns.el ends here
;;; starter-kit-bindings.el --- Set up some handy key bindings
;;
;; Part of the Emacs Starter Kit.
;; You know, like Readline.
(global-set-key (kbd "C-M-h") 'backward-kill-word)
;; Align your code in a pretty way.
(global-set-key (kbd "C-x \\") 'align-regexp)
;; Completion that uses many different methods to find options.
(global-set-key (kbd "M-/") 'hippie-expand)
;; Perform general cleanup.
(global-set-key (kbd "C-c n") 'cleanup-buffer)
;; Turn on the menu bar for exploring new modes
(global-set-key (kbd "C-<f10>") 'menu-bar-mode)
;; Font size
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
;; Use regex searches by default.
(global-set-key (kbd "C-s") 'isearch-forward-regexp)
(global-set-key (kbd "\C-r") 'isearch-backward-regexp)
(global-set-key (kbd "C-M-s") 'isearch-forward)
(global-set-key (kbd "C-M-r") 'isearch-backward)
;; File finding
(global-set-key (kbd "C-x M-f") 'ido-find-file-other-window)
(global-set-key (kbd "C-x C-M-f") 'find-file-in-project)
(global-set-key (kbd "C-x f") 'recentf-ido-find-file)
(global-set-key (kbd "C-c y") 'bury-buffer)
(global-set-key (kbd "C-c r") 'revert-buffer)
(global-set-key (kbd "M-`") 'file-cache-minibuffer-complete)
(global-set-key (kbd "C-x C-b") 'ibuffer)
;; Window switching. (C-x o goes to the next window)
(windmove-default-keybindings) ;; Shift+direction
(global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1))) ;; back one
(global-set-key (kbd "C-x C-o") (lambda () (interactive) (other-window 2))) ;; forward two
;; Start eshell or switch to it if it's active.
(global-set-key (kbd "C-x m") 'eshell)
;; Start a new eshell even if one is active.
(global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t)))
;; Start a regular shell if you prefer that.
(global-set-key (kbd "C-x M-m") 'shell)
;; If you want to be able to M-x without meta (phones, etc)
(global-set-key (kbd "C-x C-m") 'execute-extended-command)
;; Fetch the contents at a URL, display it raw.
(global-set-key (kbd "C-x C-h") 'view-url)
;; Help should search more than just commands
(global-set-key (kbd "C-h a") 'apropos)
;; Should be able to eval-and-replace anywhere.
(global-set-key (kbd "C-c e") 'eval-and-replace)
;; For debugging Emacs modes
(global-set-key (kbd "C-c p") 'message-point)
;; So good!
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-c q") 'join-line)
;; This is a little hacky since VC doesn't support git add internally
(eval-after-load 'vc
(define-key vc-prefix-map "i" '(lambda () (interactive)
(if (not (eq 'Git (vc-backend buffer-file-name)))
(vc-register)
(shell-command (format "git add %s" buffer-file-name))
(message "Staged changes.")))))
;; Activate occur easily inside isearch
(define-key isearch-mode-map (kbd "C-o")
(lambda () (interactive)
(let ((case-fold-search isearch-case-fold-search))
(occur (if isearch-regexp isearch-string (regexp-quote isearch-string))))))
;;; starter-kit-bindings.el ends here
;;; starter-kit-misc.el --- Things that don't fit anywhere else
;;
;; Part of the Emacs Starter Kit
(when window-system
(setq frame-title-format '(buffer-file-name "%f" ("%b")))
(tooltip-mode -1)
(mouse-wheel-mode t)
(blink-cursor-mode -1))
(add-hook 'before-make-frame-hook 'turn-off-tool-bar)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(ansi-color-for-comint-mode-on)
(setq visible-bell t
fringe-mode (cons 4 0)
echo-keystrokes 0.1
font-lock-maximum-decoration t
inhibit-startup-message t
transient-mark-mode t
color-theme-is-global t
shift-select-mode nil
mouse-yank-at-point t
require-final-newline t
truncate-partial-width-windows nil
uniquify-buffer-name-style 'forward
ffap-machine-p-known 'reject
whitespace-style '(trailing lines space-before-tab
face indentation space-after-tab)
whitespace-line-column 100
ediff-window-setup-function 'ediff-setup-windows-plain
oddmuse-directory (concat dotfiles-dir "oddmuse")
xterm-mouse-mode t
save-place-file (concat dotfiles-dir "places"))
(add-to-list 'safe-local-variable-values '(lexical-binding . t))
(add-to-list 'safe-local-variable-values '(whitespace-line-column . 80))
;; Set this to whatever browser you use
;; (setq browse-url-browser-function 'browse-url-firefox)
;; (setq browse-url-browser-function 'browse-default-macosx-browser)
;; (setq browse-url-browser-function 'browse-default-windows-browser)
;; (setq browse-url-browser-function 'browse-default-kde)
;; (setq browse-url-browser-function 'browse-default-epiphany)
;; (setq browse-url-browser-function 'browse-default-w3m)
;; (setq browse-url-browser-function 'browse-url-generic
;; browse-url-generic-program "~/src/conkeror/conkeror")
;; Transparently open compressed files
(auto-compression-mode t)
;; Enable syntax highlighting for older Emacsen that have it off
(global-font-lock-mode t)
;; Highlight matching parentheses when the point is on them.
(show-paren-mode 1)
;; ido-mode is like magic pixie dust!
(when (> emacs-major-version 21)
(ido-mode t)
(setq ido-enable-prefix nil
ido-enable-flex-matching t
ido-create-new-buffer 'always
ido-use-filename-at-point 'guess
ido-max-prospects 10))
(set-default 'indent-tabs-mode nil)
(set-default 'indicate-empty-lines t)
(set-default 'imenu-auto-rescan t)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;(add-hook 'text-mode-hook 'turn-on-flyspell)
(defvar coding-hook nil
"Hook that gets run on activation of any programming mode.")
(defalias 'yes-or-no-p 'y-or-n-p)
(random t) ;; Seed the random-number generator
(defalias 'auto-revert-tail-mode 'tail-mode)
;; Hippie expand: at times perhaps too hip
(delete 'try-expand-line hippie-expand-try-functions-list)
(delete 'try-expand-list hippie-expand-try-functions-list)
(delete 'try-complete-file-name-partially hippie-expand-try-functions-list)
(delete 'try-complete-file-name hippie-expand-try-functions-list)
;; Don't clutter up directories with files~
(setq backup-directory-alist `(("." . ,(expand-file-name
(concat dotfiles-dir "backups")))))
;; nxhtml stuff
(setq mumamo-chunk-coloring 'submode-colored
nxhtml-skip-welcome t
indent-region-mode t
rng-nxml-auto-validate-flag nil)
;; Associate modes with file extensions
(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$" . diff-mode))
(add-to-list 'auto-mode-alist '("\\.css$" . css-mode))
(add-to-list 'auto-mode-alist '("\\.ya?ml$" . yaml-mode))
(add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.js\\(on\\)?$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.xml$" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.scss" . sass-mode))
(add-to-list 'auto-mode-alist '("\\.sass" . sass-mode))
(eval-after-load 'grep
'(when (boundp 'grep-find-ignored-files)
(add-to-list 'grep-find-ignored-files "target")
(add-to-list 'grep-find-ignored-files "*.class")))
;; Default to unified diffs
(setq diff-switches "-u -w")
;; Cosmetics
;; (set-face-background 'vertical-border "white")
;; (set-face-foreground 'vertical-border "white")
(eval-after-load 'diff-mode
'(progn
(set-face-foreground 'diff-added "green4")
(set-face-foreground 'diff-removed "red3")))
(eval-after-load 'mumamo
'(eval-after-load 'zenburn
'(ignore-errors (set-face-background
'mumamo-background-chunk-submode "gray22"))))
;; Platform-specific stuff
(when (eq system-type 'darwin)
;; Work around a bug on OS X where system-name is FQDN
(setq system-name (car (split-string system-name "\\."))))
;; make emacs use the clipboard
(setq x-select-enable-clipboard t)
;; Get around the emacswiki spam protection
(add-hook 'oddmuse-mode-hook
(lambda ()
(unless (string-match "question" oddmuse-post)
(setq oddmuse-post (concat "uihnscuskc=1;" oddmuse-post)))))
;;; starter-kit-misc.el ends here
;;; starter-kit-registers.el --- Set up registers
;;
;; Part of the Emacs Starter Kit
;; Registers allow you to jump to a file or other location
;; quickly. Use C-x r j followed by the letter of the register (i for
;; init.el, r for this file) to jump to it.
;; You should add registers here for the files you edit most often.
(dolist (r `((?i (file . ,(concat dotfiles-dir "init.el")))
(?b (file . ,(concat dotfiles-dir "starter-kit-bindings.el")))
(?r (file . ,(concat dotfiles-dir "starter-kit-registers.el")))))
(set-register (car r) (cadr r)))
;;; starter-kit-registers.el ends here
;;; starter-kit-eshell.el --- Making the defaults a bit saner
;;
;; Part of the Emacs Starter Kit
(setq eshell-cmpl-cycle-completions nil
eshell-save-history-on-exit t
eshell-cmpl-dir-ignore "\\`\\(\\.\\.?\\|CVS\\|\\.svn\\|\\.git\\)/\\'")
(eval-after-load 'esh-opt
'(progn
(require 'em-prompt)
(require 'em-term)
(require 'em-cmpl)
(setenv "PAGER" "cat")
(set-face-attribute 'eshell-prompt nil :foreground "turquoise1")
(add-hook 'eshell-mode-hook ;; for some reason this needs to be a hook
'(lambda () (eshell/export "TERM" "dumb")))
(when (< emacs-major-version 23)
(add-hook 'eshell-mode-hook ;; for some reason this needs to be a hook
'(lambda () (define-key eshell-mode-map "\C-a" 'eshell-bol)))
(add-to-list 'eshell-output-filter-functions 'eshell-handle-ansi-color))
;; TODO: submit these via M-x report-emacs-bug
(add-to-list 'eshell-visual-commands "ssh")
(add-to-list 'eshell-visual-commands "tail")
(add-to-list 'eshell-command-completions-alist
'("gunzip" "gz\\'"))
(add-to-list 'eshell-command-completions-alist
'("tar" "\\(\\.tar|\\.tgz\\|\\.tar\\.gz\\)\\'"))))
(defun eshell/cds ()
"Change directory to the project's root."
(eshell/cd (locate-dominating-file default-directory "src")))
;; (defun eshell/find (dir &rest opts)
;; (find-dired dir (mapconcat 'identity opts " ")))
;; (defun eshell/scp (&rest args)
;; "scp: now without colon-omitting annoyance!"
;; (when (null (remove-if-not (lambda (arg) (string-match ":" arg))
;; args))
;; (error "Surely you meant to add a colon in there somewhere?"))
;; (shell-command (mapconcat 'identity (cons "scp" args) " ")))
;; Port features from
;; http://blog.peepcode.com/tutorials/2009/shell-method-missing/shell_method_missing.rb
;; * cloning git repos, github repos
;; * downloading http urls
;; * extracting archives
;; * changing to directories
;;; starter-kit-eshell.el ends here
;;; starter-kit-lisp.el --- Some helpful Lisp code
;;
;; Part of the Emacs Starter Kit
(define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
(define-key lisp-mode-shared-map (kbd "C-c l") "lambda")
(define-key lisp-mode-shared-map (kbd "RET") 'reindent-then-newline-and-indent)
(define-key lisp-mode-shared-map (kbd "C-\\") 'lisp-complete-symbol)
(define-key lisp-mode-shared-map (kbd "C-c v") 'eval-buffer)
(defface esk-paren-face
'((((class color) (background dark))
(:foreground "grey50"))
(((class color) (background light))
(:foreground "grey55")))
"Face used to dim parentheses."
:group 'starter-kit-faces)
;;; Emacs Lisp
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'emacs-lisp-mode-hook 'esk-remove-elc-on-save)
(defun esk-remove-elc-on-save ()
"If you're saving an elisp file, likely the .elc is no longer valid."
(make-local-variable 'after-save-hook)
(add-hook 'after-save-hook
(lambda ()
(if (file-exists-p (concat buffer-file-name "c"))
(delete-file (concat buffer-file-name "c"))))))
(define-key emacs-lisp-mode-map (kbd "M-.") 'find-function-at-point)
;;; Clojure
(eval-after-load 'find-file-in-project
'(add-to-list 'ffip-patterns "*.clj"))
(defun clojure-project ()
(interactive)
(message "Deprecated in favour of M-x swank-clojure-project. Install swank-clojure from ELPA."))
;;; Enhance Lisp Modes
(eval-after-load 'paredit
;; need a binding that works in the terminal
'(define-key paredit-mode-map (kbd "M-)") 'paredit-forward-slurp-sexp))
(dolist (x '(scheme emacs-lisp lisp clojure))
(when window-system
(font-lock-add-keywords
(intern (concat (symbol-name x) "-mode"))
'(("(\\|)" . 'esk-paren-face))))
(add-hook
(intern (concat (symbol-name x) "-mode-hook")) 'turn-on-paredit)
(add-hook
(intern (concat (symbol-name x) "-mode-hook")) 'run-coding-hook))
(eval-after-load 'clojure-mode
'(font-lock-add-keywords
'clojure-mode `(("(\\(fn\\>\\)"
(0 (progn (compose-region (match-beginning 1)
(match-end 1) "ƒ")
nil))))))
(eval-after-load 'slime
'(define-key slime-mode-map (kbd "C-c p")
'slime-pprint-eval-last-expression))
(eval-after-load 'slime-repl
'(define-key slime-repl-mode-map (kbd "C-c p")
'slime-pprint-eval-last-expression))
;; starter-kit-lisp.el ends here
;;; starter-kit-perl.el --- Some helpful Perl code
;;
;; Part of the Emacs Starter Kit
(eval-after-load 'cperl-mode
'(progn
(define-key cperl-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
(define-key cperl-mode-map (kbd "C-M-h") 'backward-kill-word)))
(global-set-key (kbd "C-h P") 'perldoc)
(add-to-list 'auto-mode-alist '("\\.p[lm]$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.pod$" . pod-mode))
(add-to-list 'auto-mode-alist '("\\.tt$" . tt-mode))
;; TODO: flymake
;; TODO: electric bugaloo
;; starter-kit-perl.el ends here
;;; starter-kit-ruby.el --- Some helpful Ruby code
;;
;; Part of the Emacs Starter Kit
(eval-after-load 'ruby-mode
'(progn
;; work around possible elpa bug
(ignore-errors (require 'ruby-compilation))
(setq ruby-use-encoding-map nil)
(add-hook 'ruby-mode-hook 'inf-ruby-keys)
;; no thanks @driedtoast
(add-hook 'ruby-mode-hook 'textmate-mode)
(define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
(define-key ruby-mode-map (kbd "C-M-h") 'backward-kill-word)
(define-key ruby-mode-map (kbd "C-c l") "lambda")))
(global-set-key (kbd "C-h r") 'ri)
;; Rake files are ruby, too, as are gemspecs, rackup files, etc.
(add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.gemspec$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.ru$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Gemfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Capfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Vagrantfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.podspec$" . ruby-mode))
;; We never want to edit Rubinius bytecode or MacRuby binaries
(add-to-list 'completion-ignored-extensions ".rbc")
(add-to-list 'completion-ignored-extensions ".rbo")
;;; Rake
(defun pcomplete/rake ()
"Completion rules for the `ssh' command."
(pcomplete-here (pcmpl-rake-tasks)))
(defun pcmpl-rake-tasks ()
"Return a list of all the rake tasks defined in the current
projects. I know this is a hack to put all the logic in the
exec-to-string command, but it works and seems fast"
(delq nil (mapcar #'(lambda (line)
(if (string-match "rake \\([^ ]+\\)" line) (match-string 1 line)))
(split-string (shell-command-to-string "rake -T") "[\n]"))))
(defun rake (task)
(interactive (list (completing-read "Rake (default: default): "
(pcmpl-rake-tasks))))
(shell-command-to-string (concat "rake " (if (= 0 (length task)) "default" task))))
;; Clear the compilation buffer between test runs.
(eval-after-load 'ruby-compilation
'(progn
(defadvice ruby-do-run-w/compilation (before kill-buffer (name cmdlist))
(let ((comp-buffer-name (format "*%s*" name)))
(when (get-buffer comp-buffer-name)
(with-current-buffer comp-buffer-name
(delete-region (point-min) (point-max))))))
(ad-activate 'ruby-do-run-w/compilation)))
(add-hook 'ruby-mode-hook 'run-coding-hook)
;;; Flymake
(defun flymake-ruby-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
;; Invoke ruby with '-c' to get syntax checking
(list "ruby" (list "-c" local-file))))
(defun flymake-ruby-enable ()
(when (and buffer-file-name
(file-writable-p
(file-name-directory buffer-file-name))
(file-writable-p buffer-file-name)
(if (fboundp 'tramp-list-remote-buffers)
(not (subsetp
(list (current-buffer))
(tramp-list-remote-buffers)))
t))
(local-set-key (kbd "C-c d")
'flymake-display-err-menu-for-current-line)
(flymake-mode t)))
(eval-after-load 'ruby-mode
'(progn
;; stop the crazy indentation
(setq ruby-deep-indent-paren-style nil)
;; always indent on newline
(define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
(require 'ruby-tools)
(require 'rvm)))
(eval-after-load 'ruby-mode
'(progn
(require 'flymake)
(push '(".+\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3)
flymake-err-line-patterns)
(add-hook 'ruby-mode-hook 'flymake-ruby-enable)))
;; Rinari (Minor Mode for Ruby On Rails)
(setq rinari-major-modes
(list 'mumamo-after-change-major-mode-hook 'dired-mode-hook 'ruby-mode-hook
'css-mode-hook 'yaml-mode-hook 'javascript-mode-hook))
;; starter-kit-ruby.el ends here
;;; starter-kit-js.el --- Some helpful Javascript helpers
;;
;; Part of the Emacs Starter Kit
;; NB: js-mode is part of Emacs since version 23.2 (with an alias
;; javascript-mode). It is derived and updated from Espresso mode.
(defvar esk-js-mode-hook nil)
(defun run-esk-js-mode-hook ()
(run-hooks 'esk-js-mode-hook))
(defmacro esk-configure-javascript (name)
(let ((sym (intern name))
(mode (intern (concat name "-mode")))
(hook (intern (concat name "-mode-hook")))
(keymap (intern (concat name "-mode-map")))
(indent (intern (concat name "-indent-level"))))
`(progn
(autoload ',mode ,name ,(concat "Start " name "-mode") t)
(add-to-list 'auto-mode-alist '("\\.js$" . ,mode))
(add-to-list 'auto-mode-alist '("\\.json$" . ,mode))
(add-hook ',hook 'moz-minor-mode)
(add-hook ',hook 'esk-paredit-nonlisp)
(add-hook ',hook 'run-coding-hook)
(add-hook ',hook 'run-esk-js-mode-hook)
(setq ,indent 2)
(eval-after-load ',sym
'(progn (define-key ,keymap "{" 'paredit-open-curly)
(define-key ,keymap "}" 'paredit-close-curly-and-newline)
(define-key ,keymap (kbd ",") 'self-insert-command))))))
(defun pretty-functions ()
(font-lock-add-keywords
nil `(("\\(function *\\)("
(0 (progn (compose-region (match-beginning 1)
(match-end 1) "ƒ")
nil))))))
(add-hook 'esk-js-mode-hook 'pretty-functions)
(add-hook 'js-mode-hook (lambda () (yas/minor-mode-on)))
(if (< (string-to-number emacs-version) 23.2)
(esk-configure-javascript "espresso")
(esk-configure-javascript "js"))
;;; starter-kit-js.el ends here
;;; Rust customizations
(add-hook 'rust-mode-hook 'cargo-minor-mode)
(add-hook 'rust-mode-hook
(lambda ()
(local-set-key (kbd "C-c <tab>") #'rust-format-buffer)))
(setq racer-cmd "~/.cargo/bin/racer") ;; Rustup binaries PATH
(setq racer-rust-src-path "~/Projects/rust/src") ;; Rust source code PATH
(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'company-mode)
;;; Python Customizations
(elpy-enable)
(pyenv-mode)
(defun pyvenv-autoload ()
(require 'projectile)
(let* ((pdir (projectile-project-root)) (pfile (concat pdir "venv")))
(if (file-exists-p pfile)
(pyvenv-activate pfile))))
(add-hook 'elpy-mode-hook 'pyvenv-autoload)
(defun pyenv-autoload ()
"Automatically activates pyenv version if .python-version file exists."
(f-traverse-upwards
(lambda (path)
(let ((pyenv-version-path (f-expand ".python-version" path)))
(if (f-exists? pyenv-version-path)
(pyenv-mode-set (s-trim (f-read-text pyenv-version-path 'utf-8))))))))
(add-hook 'find-file-hook 'pyenv-autoload)
(when (require 'flycheck nil t)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'flycheck-mode))
;;; Go-mode Customizations
(add-hook 'go-mode-hook
(lambda ()
(add-hook 'before-save-hook 'gofmt-before-save)
(setq tab-width 4)
(setq indent-tabs-mode 1)))
(require 'yasnippet)
(yas-global-mode 1)
(add-to-list 'default-frame-alist
'(font . "Hack-13"))
; default window width and height
(defun custom-set-frame-size ()
(add-to-list 'default-frame-alist '(height . 45))
(add-to-list 'default-frame-alist '(width . 161)))
(custom-set-frame-size)
(add-hook 'before-make-frame-hook 'custom-set-frame-size)
(load-theme 'nord t)
(add-to-list 'auto-mode-alist '("\\.js.coffee.erb$" . coffee-mode))
(add-to-list 'auto-mode-alist '("\\..*hbs.*$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.handlebars.*$" . web-mode))
(global-set-key (kbd "C-x C-f") 'find-file-other-window)
(global-set-key (kbd "<f5>") 'rg-project)
;; make Cmd key act as Meta
(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'super)
(setq mac-control-modifier 'control)
(setq ns-function-modifier 'hyper)
(setq visible-bell nil) ;; The default
(setq ring-bell-function 'ignore)
(require 'org)
(require 'org-agenda)
(require 'org-journal)
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c c") 'org-capture)
(setq org-log-done t)
(setq org-default-notes-file (concat org-directory "/notes.org"))
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "~/org/work.org" "Tasks")
"* TODO %?\n %i\n %a")
("j" "Journal" entry (file+datetree "~/org/journal.org")
"* %?\nEntered on %U\n %i\n %a")))
(server-start)
;;; init.el ends here