-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
1223 lines (1064 loc) · 37.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
;; please don't forget to install following packages
;; auto-complete popup smartscan use-package elpy js2-mode magit
;; markdown-mode multiple-cursors paredit projectile typo yaml-mode window-purpose pymacs neotree
;; pymacs
;; site-lisp gist
;; https://raw.githubusercontent.com/purcell/elisp-slime-nav/master/elisp-slime-nav.el
;; https://raw.githubusercontent.com/jorgenschaefer/comint-scroll-to-bottom/master/comint-scroll-to-bottom.el
;; https://raw.githubusercontent.com/jorgenschaefer/emacs-ixio/master/ixio.el
;; https://raw.githubusercontent.com/jorgenschaefer/legalese/master/legalese.el
;; https://raw.githubusercontent.com/jorgenschaefer/pyvenv/master/pyvenv.el
;; python packages for elpy: jedi flake8 importmagic autopep8, clone
;; https://raw.githubusercontent.com/sigma/logito/master/logito.el
;; install pcache, gist
;; this repository
;; https://github.com/sellout/emacs-color-theme-solarized.git
;; https://raw.githubusercontent.com/naiquevin/sphinx-doc.el/master/sphinx-doc.el
;; wget -O s.el https://melpa.org/packages/s-20160429.727.el
;; Bugfix until #20356 is fixed.
(set-terminal-parameter nil 'xterm--set-selection nil)
;; I dislike this fancy stuff. It's not always defined, though.
(dolist (mode '(tool-bar-mode scroll-bar-mode horizontal-scroll-bar-mode
menu-bar-mode blink-cursor-mode))
(when (fboundp mode)
(funcall mode -1)))
(when (window-system)
(set-frame-font
"-bitstream-bitstream vera sans mono-*-r-*-*-17-*-*-*-*-*-*-*")
(setq x-select-enable-primary t
x-select-enable-clipboard nil
x-stretch-cursor t
mouse-yank-at-point t))
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment "utf-8")
(prefer-coding-system 'latin-1)
(prefer-coding-system 'utf-8)
(mapc (lambda (map)
(define-key input-decode-map
(read-kbd-macro (cadr map))
(read-kbd-macro (car map))))
'(("<backtab>" "ESC [ Z")
; ("<S-up>" "ESC [1;2A")
; ("<S-down>" "ESC [1;2B")
; ("<S-right>" "ESC [1;2C")
; ("<S-left>" "ESC [1;2D")
; ("<M-up>" "ESC [1;3A")
; ("<M-down>" "ESC [1;3B")
; ("<M-right>" "ESC [1;3C")
; ("<M-left>" "ESC [1;3D")
; ("<M-S-up>" "ESC [1;4A")
; ("<M-S-down>" "ESC [1;4B")
; ("<M-S-right>" "ESC [1;4C")
; ("<M-S-left>" "ESC [1;4D")
; ("<C-up>" "ESC [1;5A")
; ("<C-down>" "ESC [1;5B")
; ("<C-right>" "ESC [1;5C")
; ("<C-left>" "ESC [1;5D")
; ("<C-prior>" "ESC [5;5~")
; ("<C-next>" "ESC [6;5~")
; ("<C-delete>" "ESC [3;5~")
; ("M", "")
))
(column-number-mode 1)
(defalias 'yes-or-no-p 'y-or-n-p)
;; Put backup files neatly away
(let ((backup-dir "~/.cache/tmp/emacs/backups")
(auto-saves-dir "~/.cache/tmp/emacs/auto-saves/"))
(dolist (dir (list backup-dir auto-saves-dir))
(when (not (file-directory-p dir))
(make-directory dir t)))
(setq backup-directory-alist `(("." . ,backup-dir))
auto-save-file-name-transforms `((".*" ,auto-saves-dir t))
auto-save-list-file-prefix (concat auto-saves-dir ".saves-")
tramp-backup-directory-alist `((".*" . ,backup-dir))
tramp-auto-save-directory auto-saves-dir))
(setq backup-by-copying t ; Don't delink hardlinks
delete-old-versions t ; Clean up the backups
version-control t ; Use version numbers on backups,
kept-new-versions 5 ; keep some new versions
kept-old-versions 2) ; and some old ones, too
;; Random default values
(setq-default
major-mode 'text-mode
;; initial-buffer-choice 'remember-notes
scroll-preserve-screen-position 'keep
user-mail-address (when (file-exists-p "~/.email")
(with-temp-buffer
(insert-file-contents "~/.email")
(goto-char (point-min))
(buffer-substring-no-properties
(point) (point-at-eol))))
inhibit-startup-message t
cursor-in-non-selected-windows nil
kill-whole-line t
switch-to-buffer-preserve-window-point t
load-prefer-newer t)
;; Case insensitivity
(setq case-fold-search t
read-file-name-completion-ignore-case t
read-buffer-completion-ignore-case t
completion-ignore-case t)
;; Clean up whitespace
(setq-default indent-tabs-mode nil
delete-trailing-lines t
require-final-newline t
show-trailing-whitespace nil)
(add-hook 'prog-mode-hook (lambda ()
(setq-local show-trailing-whitespace t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Custom commands
(global-set-key (kbd "M-SPC") 'fc/delete-space)
(defun fc/delete-space ()
"Remove all space around point.
Calling this repeatedly will clean more and more whitespace.
First, it will clear all whitespace until the end of the line, if
any. Then it will clear whitespace to the beginning of the line.
Then it will clear all following whitespace over any number of
lines. And then it will clear all preceding whitespace."
(interactive)
(cond
((looking-at "[ \t]+")
(replace-match ""))
((looking-back "[ \t]")
(let ((start (point)))
(skip-chars-backward " \t")
(delete-region (point) start)))
((looking-at "[ \t\n]+")
(replace-match ""))
((looking-back "[ \t\n]")
(let ((start (point)))
(skip-chars-backward " \t\n")
(delete-region (point) start)))))
(global-set-key [remap move-beginning-of-line] 'fc/move-beginning-of-line)
(defun fc/move-beginning-of-line ()
"Move to indentation, or beginning of the line."
(interactive)
(if (bolp)
(back-to-indentation)
(move-beginning-of-line 1))
;; (let ((current (point)))
;; (back-to-indentation)
;; (when (= (point) current)
;; (move-beginning-of-line 1)))
)
(global-set-key (kbd "C-x r a") 'fc/add-rectangle)
(defun fc/add-rectangle (start end)
"Add all the lines in the region-rectangle and put the result in the
kill ring."
(interactive "r")
(let ((sum 0))
(mapc (lambda (line)
(string-match "-?[0-9.]+" line)
(setq sum (+ sum (string-to-number (match-string 0 line)))))
(extract-rectangle start end))
(kill-new (number-to-string sum))
(message "%s" sum)))
(global-set-key (kbd "C-c e") 'fc/eval-and-replace)
(defun fc/eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(prin1 (eval (read (current-kill 0)))
(current-buffer)))
(global-set-key (kbd "C-c m") 'fc/calculate-region)
(defun fc/calculate-region (start end &optional prefix)
"Evaluate the mathematical expression within the region, and
replace it with its result.
With a prefix arg, do not replace the region, but instead put the
result into the kill ring."
(interactive "r\nP")
(let* ((expr (buffer-substring start end))
(result (fc/bc-calculate-expression expr))
(ends-with-newline (string-match "\n$" expr)))
(if prefix
(progn
(kill-new result)
(message "%s" result))
(kill-region start end)
(insert result)
(when ends-with-newline
(insert "\n")))))
(defun fc/bc-calculate-expression (expr)
"Evaluate `expr' as a mathematical expression, and return its result.
This actually pipes `expr' through bc(1), replacing newlines with
spaces first. If bc(1) encounters an error, an error is
signalled."
(with-temp-buffer
(insert expr)
(goto-char (point-min))
(while (search-forward "\n" nil t)
(replace-match " " nil t))
(goto-char (point-max))
(insert "\n")
(call-process-region (point-min)
(point-max)
"bc" t t nil "-lq")
(goto-char (point-min))
(when (search-forward "error" nil t)
(error "Bad expression"))
(while (search-forward "\n" nil t)
(replace-match "" nil t))
(buffer-string)))
(global-set-key (kbd "C-c t d") 'fc/insert-date)
(defun fc/insert-date (prefix)
"Insert the current date. With prefix-argument, use ISO format. With
two prefix arguments, write out the day and month name."
(interactive "P")
(let ((format (cond
((not prefix) "%Y-%m-%d")
((equal prefix '(4)) "%d.%m.%Y")
(t "%A, %d. %B %Y")))
(system-time-locale "de_DE"))
(insert (format-time-string format))))
(global-set-key (kbd "C-c C-u") 'fc/kill-to-beginning-of-line)
(defun fc/kill-to-beginning-of-line ()
"Kill from the beginning of the line to point."
(interactive)
(kill-region (point-at-bol)
(point)))
(global-set-key (kbd "C-x 8 p") 'fc/unicode-info-at-point)
(defun fc/unicode-info-at-point (&optional do-kill)
"Display the unicode name of the character at point."
(interactive "P")
(let ((char-code (elt (thing-at-point 'char) 0))
name)
(setq name (get-char-code-property char-code 'name))
(when (or (not name)
(= ?< (elt name 0)))
(setq name (get-char-code-property char-code 'old-name)))
(when do-kill
(kill-new name))
(message "%s" name)))
(defun rename-buffer-and-file (new-file-name)
"Rename the current buffer's file to NEW-FILE-NAME.
Also, rename the buffer and attach it to the new file."
(interactive
(list (read-file-name "Rename to: "
nil buffer-file-name
nil buffer-file-name)))
(rename-file buffer-file-name
new-file-name)
(rename-buffer (file-name-nondirectory new-file-name)
t)
(setq buffer-file-name new-file-name)
(normal-mode))
(global-set-key (kbd "C-c u") 'unfill-paragraph)
(defun unfill-paragraph ()
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(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 "
"magnaaliqua. 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 google (what)
"Use google to search for WHAT."
(interactive "sSearch: ")
(browse-url (format "http://www.google.de/search?q=%s" what)))
(defun leo (word)
(interactive "sWord: ")
(browse-url (format "http://dict.leo.org/?search=%s" word)))
(global-set-key (kbd "C-c l") 'leo-at-point)
(defun leo-at-point ()
"Open the Leo dictionary for the word at point."
(interactive)
(let ((word (thing-at-point 'word)))
(if (not word)
(error "No word found at point")
(browse-url (format "http://dict.leo.org/?search=%s#results"
word)))))
(defun fc/htmlfontify-buffer-or-region (for-blog-p)
"Show the current buffer or region if active as HTML in a temporary buffer.
This uses `htmlfontify'."
(interactive "P")
(let ((hfy-page-footer (lambda (filename)
""))
(hfy-page-header (lambda (filename stylesheet)
(if for-blog-p
"<link href=\"http://www.jorgenschaefer.de/css/elisp.css\" rel=\"stylesheet\" type=\"text/css\">\n"
""))))
(if (region-active-p)
(let ((text (buffer-substring (region-beginning)
(region-end))))
(with-temp-buffer
(insert text)
(switch-to-buffer (htmlfontify-buffer))))
(switch-to-buffer (htmlfontify-buffer)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Various global modes shipped with Emacs
;;;;;;;;;;;;;
;; compile.el
(global-set-key (kbd "<f5>") 'recompile)
;;;;;;;;;;;;
;; delsel.el
(load "delsel" nil t)
(delete-selection-mode 1)
;;;;;;;;;;
;; diff.el
(setq diff-switches "-u")
;;;;;;;;;;;;;;;
;; elec-pair.el
(when (load "elec-pair" t t)
(electric-pair-mode 1)
(defun fc/electric-pair-inhibit (char)
"Return t if we want to not pair this char.
Don't pair the closing paren in :-("
(or (and (eq char ?\()
(looking-back ":-("))
(electric-pair-default-inhibit char)))
(setq electric-pair-inhibit-predicate 'fc/electric-pair-inhibit)
(global-set-key (kbd "M-\"") 'fc/electric-pair-meta-quote)
(defun fc/electric-pair-meta-quote ()
"Wrap quotes around the following symbol."
(interactive)
(insert "\"")
(save-excursion
(forward-sexp 1)
(insert "\"")))
(global-set-key (kbd "M-(") 'fc/electric-pair-meta-paren)
(defun fc/electric-pair-meta-paren ()
"Wrap parens around the following symbol."
(interactive)
(insert "(")
(save-excursion
(forward-sexp 1)
(insert ")"))))
;;;;;;;;;;;;;;
;; electric.el
(load "electric" nil t)
(electric-indent-mode 1)
;;;;;;;;;
;; eww.el
(when (not (getenv "DISPLAY"))
(when (load "eww" nil t)
(setq browse-url-browser-function 'eww-browse-url)))
;;;;;;;;;;
;; ffap.el
(global-set-key (kbd "C-c f") 'find-file-at-point)
;;;;;;;;;;;;;;;;
;; hippie-exp.el
(load "hippie-exp" nil t)
(global-set-key (kbd "M-/") 'hippie-expand)
;; Full-line completion is *annoying*
(setq hippie-expand-try-functions-list
(delq 'try-expand-list
(delq 'try-expand-line
hippie-expand-try-functions-list)))
;;;;;;;;;;;;;
;; ibuffer.el
(global-set-key (kbd "C-x C-b") 'ibuffer)
(add-hook 'ibuffer-hook 'fc/ibuffer-group-buffers)
(defun fc/ibuffer-group-buffers ()
(setq ibuffer-show-empty-filter-groups nil)
(setq ibuffer-filter-groups
(append
;; (ibuffer-vc-generate-filter-groups-by-vc-root)
'(("Circe"
(or (mode . circe-channel-mode)
(mode . circe-query-mode)
(mode . circe-server-mode))))
;; (ibuffer-projectile-generate-filter-groups)
))
(unless (eq ibuffer-sorting-mode 'alphabetic)
(ibuffer-do-sort-by-alphabetic)))
;;;;;;;;;
;; ido.el
(load "ido" nil t)
(ido-mode 1)
(setq ido-everywhere t
ido-confirm-unique-completion t
;; This is cute. Except when you want to open a new file, then
;; it's annoying as hell.
ido-auto-merge-work-directories-length -1
ido-enable-flex-matching t)
(add-hook 'ido-setup-hook 'fc/ido-setup)
(defun fc/ido-setup ()
(define-key ido-common-completion-map (kbd "C-c")
(make-sparse-keymap))
(define-key ido-common-completion-map (kbd "C-c C-u")
'fc/ido-copy-selection)
(define-key ido-file-dir-completion-map (kbd "<up>")
'ido-prev-work-directory)
(define-key ido-file-dir-completion-map (kbd "<down>")
'ido-next-work-directory))
(defun fc/ido-copy-selection ()
"Copy the current ido selection to the kill ring."
(interactive)
(kill-new (abbreviate-file-name (concat ido-current-directory
ido-text))))
;;;;;;;;;;;;;;
;;; isearch.el
(define-key isearch-mode-map (kbd "C-d") 'fc/isearch-yank-symbol)
(defun fc/isearch-yank-symbol ()
"Yank the symbol at point into the isearch minibuffer.
C-w does something similar in isearch, but it only looks for the
rest of the word. I want to look for the whole string. And
symbol, not word, as I need this for programming the most."
(interactive)
(isearch-yank-string
(save-excursion
(when (and (not isearch-forward)
isearch-other-end)
(goto-char isearch-other-end))
(thing-at-point 'symbol))))
;;;;;;;;;;;;;;;;
;; newcomment.el
(setq comment-style 'extra-line
comment-auto-fill-only-comments t)
(add-hook 'prog-mode-hook 'auto-fill-mode)
;;;;;;;;;;;
;; paren.el
(load "paren" nil t)
(setq show-paren-delay 0
show-paren-style 'parenthesis)
(show-paren-mode 1)
;;;;;;;;;;;;;;;
;; pcomplete.el
;; I prefer bash-style to zsh-style
(setq pcomplete-cycle-completions nil)
;;;;;;;;;;;;;;;;
;; paragraphs.el
(load "paragraphs" nil t)
;; Single dash starts a paragraph
(setq paragraph-start "- \\|\f\\|[ \t]*$"
paragraph-separate "[\f\t ]*$"
sentence-end-double-space nil)
;;;;;;;;;;;;;;;
;; saveplace.el
(load "saveplace" nil t)
(setq-default save-place t)
;;;;;;;;;;;;;;;
;; sh mode hook
(defun my-shell-mode-setup-imenu ()
(setq imenu-generic-expression (append '((nil "^\\([A-Z_]+\\)=.*" 1))
(nthcdr 1 (car sh-imenu-generic-expression)))))
(add-hook 'sh-mode-hook 'my-shell-mode-setup-imenu)
;;;;;;;;;;;;
;; server.el
(load "server" nil t)
(when (not (server-running-p server-name))
(server-start))
;;;;;;;;;;;;;
;; subword.el
(load "subword" nil t)
(global-subword-mode)
(let ((elt (assq 'subword-mode minor-mode-alist)))
(when elt
(setcdr (assq 'subword-mode minor-mode-alist) '(""))))
;;;;;;;;;;
;; time.el
(load "time" nil t)
(setq display-time-24hr-format t)
(display-time)
;; Some nice times for M-x display-time-world
(setq display-time-world-list '(("America/New_York" "Sarasota")
("Europe/Warsaw" "Warsaw")
))
;;;;;;;;;;;;;;;;;
;;; time-stamp.el
(add-hook 'before-save-hook 'time-stamp)
;;;;;;;;;;;;
;;; tramp.el
(require 'cl-lib)
(setq file-name-handler-alist
(cl-remove-if (lambda (elt)
(string-match "tramp" (symbol-name (cdr elt))))
file-name-handler-alist))
;;;;;;;;;;;;;;;
;;; uniquify.el
(load "uniquify" nil t)
(setq-default uniquify-buffer-name-style 'post-forward)
;;;;;;;;
;; vc.el
(setq vc-diff-switches diff-switches)
;;;;;;;;;;;;;;
;; windmove.el
(global-set-key (kbd "C-x <C-up>") 'windmove-up)
(global-set-key (kbd "C-x <C-down>") 'windmove-down)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
;;;;;;;;;;;;
;; winner.el
(winner-mode 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Various major modes shipped with Emacs
;;;;;;;;;;
;;; c-mode
(add-hook 'c-mode-hook 'fc/c-setup)
(defun fc/c-setup ()
"Set up C mode for my needs."
(c-set-style "k&r")
(setq c-basic-offset 4)
(c-set-offset 'case-label '+)
(c-set-offset 'inextern-lang 0))
;;;;;;;;;;;;;;
;; comint-mode
(load "comint" nil t)
(add-hook 'comint-mode-hook 'fc/init-comint)
(defun fc/init-comint ()
;; Don't jump around when output in a buffer happens
(set (make-local-variable 'scroll-conservatively) 1000))
(add-to-list 'comint-output-filter-functions
'comint-watch-for-password-prompt)
(ansi-color-for-comint-mode-on)
;;;;;;;;;;;;;;;;;;;
;; compilation-mode
(load "compile" nil t)
(load "ansi-color" nil t)
(defun fc/colorize-compilation-buffer ()
(let ((inhibit-read-only t))
(ansi-color-apply-on-region (point-min) (point-max))))
(add-hook 'compilation-filter-hook 'fc/colorize-compilation-buffer)
;;;;;;;;;;;;;;;;;;
;; emacs-lisp-mode
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(defun elisp-check ()
"Check the current buffer for possible elisp problems.
This actually byte compiles the buffer, but throws away the
result and keeps only the warnings."
(interactive)
(let ((lisp (buffer-substring-no-properties (point-min)
(point-max))))
(with-temp-buffer
(setq buffer-file-coding-system nil)
(set-buffer-multibyte t)
(insert lisp)
(let ((byte-compile-log-buffer (format "*Check for %s*"
(buffer-name)))
(byte-compile-verbose nil))
(byte-compile-from-buffer (current-buffer))))))
;;;;;;;;;;;;;
;;; html-mode
(load "sgml-mode" nil t)
(add-hook 'html-mode-hook
(lambda ()
;; Default indentation is usually 2 spaces,
;; changing to 4.
(set (make-local-variable 'sgml-basic-offset) 4)))
(define-key html-mode-map (kbd "C-c RET") 'fc/html-toggle-paragraph)
(defun fc/html-toggle-paragraph ()
"Add or remove HTML paragraph tags from the current paragraph"
(interactive)
(save-excursion
(backward-paragraph)
(when (looking-at "^\\s-*$")
(forward-char 1))
(if (looking-at "<p>")
(replace-match "")
(insert "<p>"))
(forward-paragraph)
(when (looking-at "^\\s-*$")
(backward-char 1))
(if (looking-back "</p>")
(replace-match "")
(insert "</p>"))))
(define-key html-mode-map (kbd "&") 'fc/html-insert-quoted)
(defun fc/html-insert-quoted (char)
"Insert a & character.
Depending on the subsequent character, insert an appropriate HTML
glyph."
(interactive "cInsert: ")
(case char
((?&)
(insert "&"))
((?<)
(insert "<"))
((?>)
(insert ">"))
((?\s)
(insert " "))
((34) ; "
(insert """))
(t
(insert (format "&#x%02x;" char)))))
;;;;;;;;;;;;;;;;;;;
;;; javascript-mode
;; For json only, really. js2-mode doesn't do a good job with json.
(load "js")
(setq-default js-indent-level 4)
;;;;;;;;;;;;;;;
;;; python-mode
(load "python" nil t)
(when (executable-find "flake8")
(setq python-check-command "flake8"))
(add-hook 'python-mode-hook
(lambda ()
(setq electric-indent-chars '(10))))
;;;;;;;;;;;;;;
;; scheme-mode
;; Make parens less visible
(font-lock-add-keywords 'scheme-mode '(("[()]" . 'paren-face)))
(defface paren-face
'((t (:foreground "gray60")))
"The face used for parenthesises."
:group 'scheme)
;;;;;;;;;;;;;
;; shell-mode
(load "shell" nil t)
;; > may show up in some prompts
(setq shell-prompt-pattern "^[^#$%\n]*[#$%>] *")
(global-set-key (kbd "C-c s") 'fc/toggle-shell)
(global-set-key (kbd "C-c c p") 'python-shell-switch-to-shell)
(defun fc/toggle-shell ()
"Switch between the last active buffer and the shell."
(interactive)
(if (eq major-mode 'shell-mode)
(let ((buf (catch 'return
(dolist (buf (cdr (buffer-list)))
(when (not (string-prefix-p " " (buffer-name buf)))
(throw 'return buf)))
nil)))
(when buf
(switch-to-buffer buf)))
(shell)))
(define-key shell-mode-map (kbd "C-c C-y") 'fc/shell-switch-dir)
(defun fc/shell-switch-dir ()
"Switch `shell-mode' to the `default-directory' of the last buffer."
(interactive)
(when (eq major-mode 'shell-mode)
(let* ((dir (catch 'return
(dolist (buf (buffer-list))
(with-current-buffer buf
(when buffer-file-name
(throw 'return default-directory)))))))
(goto-char (process-mark (get-buffer-process (current-buffer))))
(insert (format "cd %s" (shell-quote-argument dir)))
(let ((comint-eol-on-send nil))
(comint-send-input)))))
;;;;;;;;;;;;
;; text-mode
(add-hook 'text-mode-hook 'fc/text-mode-init)
(defun fc/text-mode-init ()
(setq-local electric-pair-preserve-balance nil))
(setq next-line-add-newlines t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Third party extensions
(when (file-directory-p "~/.emacs.d/site-lisp")
(rename-file "~/.emacs.d/site-lisp" "~/.emacs.d/lisp"))
(when (file-directory-p "~/.emacs.d/lisp")
(add-to-list 'load-path "~/.emacs.d/lisp")
(dolist (dirname (directory-files "~/.emacs.d/lisp" t "^[^.]"))
(when (file-directory-p dirname)
(add-to-list 'load-path dirname))))
(load "package" nil t)
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa-stable" . "http://stable.melpa.org/packages/")
("melpa" . "http://melpa.org/packages/")
("elpy" . "http://jorgenschaefer.github.io/packages/")))
(setq package-archive-priorities '(("melpa" . -100))
package-enable-at-startup nil)
(package-initialize)
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; comint-scroll-to-bottom
(when (load "comint-scroll-to-bottom" t t)
(add-hook 'comint-mode-hook 'comint-add-scroll-to-bottom))
;;;;;;;;;;;;;;;;;;
;; elisp-slime-nav
(when (load "elisp-slime-nav" t t)
(define-key elisp-slime-nav-mode-map (kbd "M-,") nil)
(add-hook 'emacs-lisp-mode-hook 'elisp-slime-nav-mode)
(add-hook 'lisp-interaction-mode-hook 'elisp-slime-nav-mode))
;;;;;;;
;; elpy
(when (load "elpy" t t)
(elpy-enable)
(global-set-key (kbd "C-c ,") 'elpy-multiedit)
(add-hook 'pyvenv-post-activate-hooks 'fc/configure-elpy-from-env)
;; (elpy-use-ipython)
(defun fc/configure-elpy-from-env ()
(dolist (elt process-environment)
(when (string-match "\\`\\(ELPY_[^=]*\\)=\\(.*\\)\\'" elt)
(let ((var (downcase
(replace-regexp-in-string "_" "-" (match-string 1 elt))))
(val (match-string 2 elt)))
(set (intern var) (read val))))))
)
;;;;;;;
;; ixio
(load "ixio" t t)
;;;;;;;;;;;
;; js2-mode
(when (load "js2-mode" t t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(add-hook 'js2-mode-hook 'auto-complete-mode)
(setq-default js2-highlight-level 3
js2-mode-indent-ignore-first-tab t
js2-mode-indent-inhibit-undo t
js2-global-externs '("$")
js2-basic-offset 4
js2-global-externs
'(;; AngularJS
"angular" "module" "inject"
;; Jasmine
"describe" "it" "expect" "beforeEach" "spyOn")
)
(define-key js2-mode-map (kbd "C-c C-n") 'js2-next-error)
(defadvice js2-mode-toggle-element (before ad-move-to-toggle-element
activate)
"Move to a sensible location first"
(interactive)
(let* ((start (line-beginning-position))
(end (line-end-position))
(invisible (next-single-property-change start 'invisible nil end))
(brace (save-excursion
(goto-char start)
(re-search-forward "{" end t))))
(cond
(invisible (goto-char invisible))
(brace (goto-char brace))))))
;;;;;;;;;;;
;; legalese
(load "legalese" t t)
;;;;;;;;
;; magit
(setq magit-last-seen-setup-instructions "1.4.0")
(when (load "magit" t t)
(global-set-key (kbd "C-x v g") 'magit-status)
(global-set-key (kbd "C-x v a") 'vc-annotate))
;;;;;;;;;;;;;;;;;
;;; markdown-mode
(when (load "markdown-mode" t t)
(add-hook 'markdown-mode-hook 'flyspell-mode)
(setq markdown-command "markdown_py"
markdown-italic-underscore t
markdown-indent-on-enter nil
markdown-follow-wiki-link-on-enter nil
)
(add-to-list 'auto-mode-alist '("\\.md" . markdown-mode))
(define-key markdown-mode-map (kbd "TAB") 'markdown-cycle)
(define-key markdown-mode-map (kbd "<backtab>") 'markdown-shifttab)
(define-key markdown-mode-map (kbd "C-M-f") 'forward-sexp)
(define-key markdown-mode-map (kbd "C-M-b") 'backward-sexp)
(define-key markdown-mode-map (kbd "C-c C-x") 'fc/markdown-code-block)
(defun fc/markdown-code-block (beg end)
"Wrap the current region into a code block."
(interactive "r")
(save-excursion
(goto-char end)
(when (not (bolp))
(insert "\n"))
(insert "```\n")
(goto-char beg)
(forward-line 0)
(insert "```\n")))
(define-key markdown-mode-map (kbd "C-c C-n") 'fc/markdown-next-header)
(defun fc/markdown-next-header ()
"Go to the next header in the file."
(interactive)
(let ((next-header (save-excursion
(forward-line 1)
(re-search-forward "^#" nil t))))
(if (not next-header)
(error "No next header")
(goto-char next-header)
(goto-char (point-at-bol)))))
(define-key markdown-mode-map (kbd "C-c C-p") 'fc/markdown-previous-header)
(defun fc/markdown-previous-header ()
"Go to the previous header in the file."
(interactive)
(let ((previous-header (save-excursion
(forward-line -1)
(re-search-backward "^#" nil t))))
(if (not previous-header)
(error "No previous header")
(goto-char previous-header)
(goto-char (point-at-bol)))))
(defun markdown-check-change-for-wiki-link (&rest ignored)
"Do nothing.
The default markdown implementation exhibits a bug. You can
reproduce it using the following:
M-: (when (looking-at \"\") (replace-match \"abc\"))
This will insert \"abc\" at the current point, but move point
down one line. Removing `markdown-check-change-for-wiki-link'
from `after-change-functions' fixes that."
nil)
)
;;;;;;;;;;;;;;;;;;;;;;;;
;; Multiple Cursors Mode
(when (load "multiple-cursors" t t)
(global-set-key (kbd "<M-S-up>") 'mc/mark-previous-lines)
(global-set-key (kbd "<M-S-down>") 'mc/mark-next-lines)
(global-set-key (kbd "C-M-j") 'fc/mark-next-like-this)
(global-set-key (kbd "<M-S-return>") 'fc/mark-next-like-this)
(defun fc/mark-next-like-this (arg)
(interactive "p")
(when (not (use-region-p))
(let* ((end (progn
(forward-sexp)
(point)))
(beg (progn
(backward-sexp)
(point))))
(goto-char end)
(set-mark beg)))
(mc/mark-next-like-this arg)))
;;;;;;;;;;;
;; Org Mode
;; This actually comes with Emacs, but we want to use the one from GNU
;; ELPA as it is more current, hence it's down here.
(when (load "org" t t)
(modify-syntax-entry ?\' "." org-mode-syntax-table)
(define-key org-mode-map (kbd "C-c a") 'fc/org-agenda)
(define-key org-mode-map (kbd "C-c ,") nil)
(defun fc/org-agenda ()
(interactive)
(when (get-buffer "google-calendar.org")
(kill-buffer "google-calendar.org"))
(org-agenda nil (caar org-agenda-custom-commands)))
(setq org-fontify-emphasized-text nil
org-tags-column -76
org-agenda-files nil
org-descriptive-links nil
org-agenda-include-diary nil
org-agenda-start-on-weekday nil
org-todo-keywords '((sequence "TODO"
"DONE"
"WAITING"
"SCHEDULED"
"ONGOING"))
org-agenda-custom-commands '(("t" "General TODO agenda"
((todo "TODO")
(agenda "")
(todo "WAITING")))))
(dolist (filename '("~/Documents/Notes/Todo"
"~/Files/google-calendar.org"))
(when (file-exists-p filename)
(add-to-list 'org-agenda-files filename t)))
)
;;;;;;;;;;
;; paredit
(when (load "paredit" t t)
(define-key paredit-mode-map (kbd "RET") 'newline)
(define-key paredit-mode-map (kbd "C-j") 'paredit-newline)
(define-key paredit-mode-map (kbd "<C-left>") 'paredit-forward-barf-sexp)
(define-key paredit-mode-map (kbd "<C-right>") 'paredit-forward-slurp-sexp)
(define-key paredit-mode-map (kbd "M-q") 'paredit-reindent-defun)
(add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook 'enable-paredit-mode)
(add-hook 'scheme-mode-hook 'enable-paredit-mode))
;;;;;;;;;;;;;
;; projectile
(when (load "projectile" t t)
(projectile-global-mode)
(projectile-mode))
;;;;;;;;;
;; pyvenv
(when (load "pyvenv" t t)
(defalias 'workon 'pyvenv-workon)
(pyvenv-mode))
;;;;;;;;;;
;; typo.el
(when (load "typo" t t)
(dolist (hook '(markdown-mode-hook html-mode-hook))
(add-hook hook 'typo-mode)))
;;;;;;;;;;;;
;; yaml-mode
(when (load "yaml-mode" t t)
(define-key yaml-mode-map (kbd "C-j") nil)
(add-to-list 'auto-mode-alist '("\\.sls\\'" . yaml-mode)))
;; auto-complete config
(ac-config-default)
;; dirty fix for having AC everywhere
(define-globalized-minor-mode real-global-auto-complete-mode
auto-complete-mode (lambda ()
(if (not (minibufferp (current-buffer)))
(auto-complete-mode 1))
))
(real-global-auto-complete-mode t)
(setq ac-auto-start 3)
;; adjusting copy buffers, want to work with os buffer instead of emacs buffer
(xterm-mouse-mode 0)
(defun copy-to-clipboard ()