forked from gorakhargosh/gemacs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.el
More file actions
1285 lines (1074 loc) · 44.9 KB
/
init.el
File metadata and controls
1285 lines (1074 loc) · 44.9 KB
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 in a single file.
;;
;; Copyright (C) 2012 Google Inc.
;;
;; 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;
;; Author: yesudeep@google.com (Yesudeep Mangalapilly)
;;
;;; This file is NOT a part of GNU Emacs.
;;
;;; Commentary:
;;
;;; Code:
(eval-when-compile
(require 'cl))
;; Dear Emacs, please don't make me wait at startup.
(modify-frame-parameters nil '((wait-for-wm . nil)))
(setq redisplay-dont-pause t)
(set-locale-environment "en_US.UTF-8")
;; ======================================================================
;; Initial configuration.
;; ======================================================================
;; (setq user-emacs-directory (file-name-directory (or (buffer-file-name)
;; load-file-name)))
(add-to-list 'load-path user-emacs-directory)
;; Directory paths.
(setq goog-site-lisp-dir (expand-file-name
(concat user-emacs-directory "site-lisp")))
;; Load-path.
(add-to-list 'load-path goog-site-lisp-dir)
;; Add all subdirectories of site-lisp to load path.
(let ((default-directory goog-site-lisp-dir))
(normal-top-level-add-subdirs-to-load-path))
;; Network-specific configuration is loaded from goog-network-dir.
(setq goog-network-name "corp.google.com"
goog-network-dir (format "~/.%s/emacs.d/" goog-network-name)
goog-network-re ".*[.]corp[.]google[.]com")
;; ======================================================================
;; Platform detection.
;; ======================================================================
(defun goog/platform/is-darwin-p ()
"Determines whether the system is darwin-based (Mac OS X)"
(interactive)
(string-equal system-type "darwin"))
(defun goog/platform/is-linux-p ()
"Determines whether the system is GNU/Linux-based."
(interactive)
(string-equal system-type "gnu/linux"))
;; ======================================================================
;; Package management.
;; ======================================================================
;; ----------------------------------------------------------------------
;; El-get
;; ----------------------------------------------------------------------
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.github.com/dimitri/el-get/master/el-get-install.el")
(let (el-get-master-branch)
(goto-char (point-max))
(eval-print-last-sexp))))
(setq
el-get-sources
'(el-get
(:name smex ;; a better (ido-like) M-x
:after (progn
(setq smex-save-file "~/.emacs.d/.smex-items")
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)))
(:name go-mode
:website "http://github.com/dominikh/go-mode.el#readme"
:description "An improved go-mode."
:type github
:pkgname "dominikh/go-mode.el"
:post-init (progn
(require 'go-mode)))
))
(setq
goog:el-get-packages
'(
;; clojurescript-mode
;; go-autocomplete
auto-complete
diff-hl
expand-region
fill-column-indicator
js2-mode
js2-refactor
magit
powerline
))
(setq goog:el-get-packages
(append
goog:el-get-packages
(loop for src in el-get-sources collect (el-get-source-name src))))
(el-get 'sync goog:el-get-packages)
;; ----------------------------------------------------------------------
;; package.el
;; ----------------------------------------------------------------------
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar default-packages '(
ac-nrepl
ac-slime
ace-jump-mode
ack-and-a-half
auto-compile
cider
clojure-cheatsheet
clojure-mode
clojure-test-mode
dart-mode
evil-numbers
fastnav
find-things-fast
flycheck
go-autocomplete
helm
highlight-symbol
ido-ubiquitous
iedit
key-chord
markdown-mode
multiple-cursors
nav
persp-mode
rainbow-delimiters
rcirc-color
sass-mode
smartparens
sql-indent
switch-window
undo-tree
vimrc-mode
yaml-mode
yasnippet
zencoding-mode
))
(dolist (p default-packages)
(when (not (package-installed-p p))
(package-install p)))
;;------------------------------------------------------------------------------
;; End package management.
;;------------------------------------------------------------------------------
;; Autocompilation.
(add-to-list 'load-path user-emacs-directory)
(require 'auto-compile)
(auto-compile-on-load-mode 1)
(auto-compile-on-save-mode 1)
;; Load our definitions.
(require 'goog-defuns)
;; ======================================================================
;; Vanilla Emacs preferences.
;; ======================================================================
;; Maximize the Emacs frame on startup.
;; TODO(yesudeep): resolve a bug where it hides the first line of every buffer.
;;(require 'maxframe)
;;(add-hook 'window-setup-hook 'maximize-frame t)
(when window-system
(blink-cursor-mode nil)
(global-font-lock-mode 1)
(global-hl-line-mode)
(mouse-wheel-mode t)
(scroll-bar-mode -1)
(setq frame-title-format '(buffer-file-name "%f" ("%b")))
(tool-bar-mode -1)
(tooltip-mode -1)
)
(setq-default indent-tabs-mode nil
indicate-empty-lines t
indicate-buffer-boundaries (quote left)
require-final-newline t
cursor-type 'bar
;; next-line-add-newlines nil ;; Don't add newlines past EOF.
)
(setq
auto-save-file-name-transforms `((".*" ,temporary-file-directory t))
backup-directory-alist `((".*" . ,temporary-file-directory))
color-theme-is-global t
diff-switches "-u"
ediff-window-setup-function 'ediff-setup-windows-plain
inhibit-startup-message t
mouse-yank-at-point t
oddmuse-directory (concat user-emacs-directory "oddmuse")
read-file-name-completion-ignore-case 't
save-place-file (concat user-emacs-directory "places")
sentence-end-double-space nil
shift-select-mode t ;; Some of my users want this.
visible-bell t
)
(add-hook 'snippet-mode-hook (lambda ()
(setq require-final-newline nil)
;; Don't enable this for snippets.
))
(progn
(column-number-mode 1) ;; show column numbers in mode line.
(delete-selection-mode 1) ;; Overwrite selection; DWIM.
(fset 'yes-or-no-p 'y-or-n-p) ;; y or n is better than yes or no.
(global-auto-revert-mode 1) ;; Auto-reflect on-disk changes.
(global-linum-mode 1) ;; line numbers in left gutter.
(global-subword-mode t) ;; Use subword navigation.
(line-number-mode 1) ;; show line numbers in the mode line.
)
;; Cua mode without the nonsense.
;; (setq cua-enable-cua-keys nil) ;; Turn off Windows key bindings.
;; (cua-mode t) ;; Rectangular selections are awesome.
;; (cua-selection-mode nil) ;; No shift-arrow style marking.
(delete-selection-mode t)
;; Use unique buffer names.
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (concat user-emacs-directory "places"))
(setq backup-directory-alist `((".*" . "~/.emacs.d/saves")))
(setq auto-save-file-name-transforms `((".*" "~/.emacs.d/saves" t)))
;; ----------------------------------------------------------------------
;; Fonts
;; ----------------------------------------------------------------------
;; Fonts appear to be larger on Linux workstations.
(setq preferred-linux-fonts
'(
;; Monaco is available on Mac OS X and some of my Linux workstations.
"Monaco-13"
;; Used by the secure shell app on Chrome. Looks pretty.
"DejaVu Sans Mono-12"
;; Droid Sans Mono: quite nice. 15 pixels total height at 10 point.
;; Clear & crisp. (e.g.
;; http://www.fontex.org/download/Droid-sans-mono.ttf)
"Droid Sans Mono Dotted-10"
"Droid Sans Mono-10"
;; Ubuntu Linux has this.
"Ubuntu Mono-12"
;; Consolas: download installer from Microsoft.
;; Quite beautiful and renders nicely, but a little light.
;; Pretty similar to Droid Sans Mono.
;; The slanted verticals on the capital M annoy me a little.
;; (16 pixels height)
"Consolas-10.5"
;; Inconsolata: lots of people like this.
;; http://www.levien.com/type/myfonts/inconsolata.html: about same size
;; as Consolas-10.5, but thicker and less leading (17 pixels height) and
;; not as smooth lines. Feels chunky.
"Inconsolata-12"
;; default
"Courier New-10.5"))
;; Mac OS X tends to show smaller fonts.
(setq preferred-mac-fonts
'(
;; Monaco is available on Mac OS X.
"Monaco-13"
;; Used by the secure shell app on Chrome. Looks pretty.
"DejaVu Sans Mono-14"
;; Droid Sans Mono: quite nice. 15 pixels total height at 10 point.
;; Clear & crisp. (e.g.
;; http://www.fontex.org/download/Droid-sans-mono.ttf)
"Droid Sans Mono Dotted-14"
"Droid Sans Mono-14"
;; Ubuntu Linux has this but my Mac also does.
"Ubuntu Mono-18"
;; Consolas: download installer from Microsoft. Quite beautiful and
;; renders nicely, but a little light. Pretty similar to Droid Sans
;; Mono. The slanted verticals on the capital M annoy me a little. (16
;; pixels height)
"Consolas-10.5"
;; Inconsolata: lots of people like this.
;; http://www.levien.com/type/myfonts/inconsolata.html: about same size
;; as Consolas-10.5, but thicker and less leading (17 pixels height) and
;; not as smooth lines. Feels chunky.
"Inconsolata-12"
;; default
"Courier New-10.5"))
(defun find-first-font (list)
(cond ((null list) nil)
((x-list-fonts (car list))
(message (concat "Using font " (car list)))
(car list))
(t ; recurse
(find-first-font (cdr list)))
))
(when window-system
;; set default font attributes (for all frames)
(when (goog/platform/is-darwin-p)
;; Monaco is clean. The default is too small in the GUI.
;; (set-face-font 'default "Monaco-13")
;; Mac OS X-specific font anti-aliasing.
(set-face-attribute 'default nil :font (find-first-font preferred-mac-fonts))
(setq mac-allow-anti-aliasing t))
(when (goog/platform/is-linux-p)
;; Monaco is clean. The default is too small in the GUI.
;; (set-face-font 'default "Monaco-13")
;; Mac OS X-specific font anti-aliasing.
(set-face-attribute 'default nil :font (find-first-font preferred-linux-fonts)))
)
;; Scroll faster.
(setq mouse-wheel-scroll-amount '(7 ((shift) . 1) ((control) . nil)))
;; Enables mouse support scrolling when using Emacs in the terminal.
(unless window-system
(require 'mouse)
(xterm-mouse-mode t)
(global-set-key [mouse-4] '(lambda ()
(interactive)
(scroll-down 1)))
(global-set-key [mouse-5] '(lambda ()
(interactive)
(scroll-up 1)))
;; (defun track-mouse (e))
(setq mouse-sel-mode t))
;; ----------------------------------------------------------------------
;; Editing and searching.
;; ----------------------------------------------------------------------
(setq-default fill-column 80) ;; right margin and fill column.
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook 'turn-on-watchwords)
(add-hook 'prog-mode-hook 'turn-on-watchwords)
(defun goog/prog-mode-common/setup ()
"Applies settings common to all programming language modes."
(auto-fill-mode 1)
(set (make-local-variable 'fill-nobreak-predicate)
(lambda ()
(not (eq (get-text-property (point) 'face)
'font-lock-comment-face)))))
(add-hook 'prog-mode-common-hook 'goog/prog-mode-common/setup)
;; Use whitespace mode. Cleans up trailing spaces, shows tabs, unnecessary
;; whitespace, end of file newline, bad indentation, text overrunning the
;; margin, etc.
(require 'whitespace)
(global-whitespace-mode t)
(setq whitespace-style
'(face empty indentation lines-tail newline tabs trailing)
whitespace-action '(auto-cleanup warn-read-only)
whitespace-line-column 80)
;; Disabled space-mark newline-mark because it makes code very hard to read.
(setq whitespace-display-mappings
'((space-mark ?\ [?\xB7] [?.]) ;; space
(space-mark ?\xA0 [?\xA4] [?_]) ;; hard space
(newline-mark ?\n [?\xB6 ?\n] [?$ ?\n]) ;; end-of-line
))
(require 're-builder)
(setq reb-re-syntax 'string)
;; -----------------------------------------------------------------------------
;; Configure pairs of characters and parenthese matching.
;;
(require 'smartparens)
(require 'smartparens-config)
(progn
(show-paren-mode t) ;; Highlight matching parentheses.
;; (setq show-paren-delay 0
;; show-paren-style 'expression
;; )
(smartparens-global-mode t)
(show-smartparens-global-mode +1)
;; Don't automatically escape quotes within quotes.
(setq sp-autoescape-string-quote nil)
)
;; (require 'rainbow-delimiters)
;; (global-rainbow-delimiters-mode)
;; Enable this if you need it.
;; (add-hook 'prog-mode-hook '(lambda () (rainbow-mode)))
;; ----------------------------------------------------------------------
;; Clipboard and kill-ring.
;; ----------------------------------------------------------------------
(setq x-select-enable-clipboard t) ;; <3 clipboard copy-paste.
;; https://github.com/bbatsov/emacs-prelude/commit/d26924894b31d5dc3a8b2813719579baccc2b433
(when (goog/platform/is-darwin-p)
(defun goog/clipboard/copy-from-osx ()
"Pastes from the OS X clipboard."
(shell-command-to-string "pbpaste"))
(defun goog/clipboard/paste-to-osx (text &optional push)
"Copies text into the OS X clipboard."
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(setq interprogram-cut-function 'goog/clipboard/paste-to-osx
interprogram-paste-function 'goog/clipboard/copy-from-osx))
;; SlickCopy. Makes the kill commands work on the line if nothing is selected.
(defadvice kill-ring-save (before slick-copy activate compile)
"When called interactively with no active region, copy the current line."
(interactive
(if mark-active
(list (region-beginning) (region-end))
(progn
(message "Current line is copied.")
(list (line-beginning-position) (line-beginning-position 2)) ) ) ))
(defadvice kill-region (before slick-copy activate compile)
"When called interactively with no active region, cut the current line."
(interactive
(if mark-active
(list (region-beginning) (region-end))
(progn
(list (line-beginning-position) (line-beginning-position 2)) ) ) ))
;; Whitespace-aware kill-line.
(defadvice kill-line (after kill-line-cleanup-whitespace activate compile)
"Cleans up whitespace on `kill-line'."
(if (not (bolp))
(delete-region (point) (progn (skip-chars-forward " \t") (point)))))
;; -----------------------------------------------------------------------------
;; RCIRC
;; -----------------------------------------------------------------------------
;; (require 'rcirc-color)
;; ----------------------------------------------------------------------
;; File and directory navigation.
;; ----------------------------------------------------------------------
(defun ibuffer-ido-find-file ()
"`ido-find-file', but default to directory of buffer at point."
(interactive
(let ((default-directory (let ((buf (ibuffer-current-buffer)))
(if (buffer-live-p buf)
(with-current-buffer buf
default-directory)
default-directory))))
(ido-find-file-in-dir default-directory))))
(setq find-file-wildcards t)
(eval-after-load "ido"
'(progn
(ido-mode t)
(eval-after-load "ido-ubiquitous"
'(progn
(ido-ubiquitous-mode t)
))
(setq ido-save-directory-list-file (concat user-emacs-directory ".ido.last")
ido-use-filename-at-point 'guess
ido-enable-flex-matching t
confirm-nonexistent-file-or-buffer nil
ido-create-new-buffer 'always)
;; Display ido results vertically, rather than horizontally.
;; From the Emacs wiki.
(setq ido-decorations (quote ("\n-> " "" "\n " "\n ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")))
(defun goog/config/ido-mode/disable-line-truncation ()
(set (make-local-variable 'truncate-lines) nil))
(add-hook 'ido-minibuffer-setup-hook 'goog/config/ido-mode/disable-line-truncation)
(global-set-key [(control tab)] 'ido-switch-buffer)
(defun goog/config/ido-mode/cycle-with-up-and-down-arrow-keys ()
"Allow the up and down arrow keys to cycle through `ido-mode' results."
(define-key ido-completion-map (kbd "<up>") 'ido-prev-match)
(define-key ido-completion-map (kbd "<down>") 'ido-next-match)
)
(add-hook 'ido-setup-hook 'goog/config/ido-mode/cycle-with-up-and-down-arrow-keys)
))
;; ----------------------------------------------------------------------
;; Finding files, recent files and sessions.
;; ----------------------------------------------------------------------
(autoload 'recentf "recentf" t)
(setq recentf-auto-cleanup 'never) ;; Disable before we start recentf for tramp.
(recentf-mode t)
(setq recentf-max-saved-items 400)
(defun ido-recentf-open ()
"Use `ido-completing-read' to \\[find-file] a recent file."
(interactive)
(if (find-file (ido-completing-read "Find recent file: " recentf-list))
(message "Opening file...")
(message "Aborting")))
(require 'eldoc) ; if not already loaded
(require 'switch-window)
(require 'ack-and-a-half)
;; Create shorter aliases
(defalias 'ack 'ack-and-a-half)
(defalias 'ack-same 'ack-and-a-half-same)
(defalias 'ack-find-file 'ack-and-a-half-find-file)
(defalias 'ack-find-file-same 'ack-and-a-half-find-file-same)
(require 'persp-mode)
(persp-mode t)
(require 'helm-config)
(helm-mode 1)
;; ----------------------------------------------------------------------
;; goog/elisp
;; ----------------------------------------------------------------------
(defun goog/elisp/load-current-module ()
"Load the current Elisp module."
(interactive)
(load-file buffer-file-name))
(defun goog/elisp/load-directory (dir)
"Load all elisp modules from the given DIR directory."
(when (file-exists-p dir)
(mapc 'load (directory-files dir t "^[^#].*el"))))
(defun goog/elisp/load-if-exists (name)
"Load an elisp with the given NAME module if it exists."
(when (file-exists-p name)
(load name)))
(defun goog/elisp/reload-configuration ()
"Reloads the init.el module from the Emacs configuration directory."
(interactive)
;; (load-file (concat user-emacs-directory "init.el"))
(load-file (concat user-emacs-directory "init.el"))
(yas-reload-all))
(defun goog/elisp/eval-after-init (form)
"Add `(lambda () FORM)' to `after-init-hook'.
If Emacs has already finished initialization, also eval FORM
immediately."
(let ((func (list 'lambda nil form)))
(add-hook 'after-init-hook func)
(when after-init-time
(eval form))))
;; ======================================================================
;; Packages
;; ======================================================================
;; Git integration.
(autoload 'magit-status "magit" nil t)
(global-set-key (kbd "C-x g") 'magit-status)
(eval-after-load "magit"
'(progn
(setq magit-completing-read-function 'magit-ido-completing-read)
))
(require 'undo-tree)
(autoload 'nav "nav" nil t)
(global-set-key (kbd "C-x C-a") 'nav)
(autoload 'move-text-up "move-text" nil t)
(autoload 'move-text-down "move-text" nil t)
(global-set-key [M-s-up] 'move-text-up)
(global-set-key [M-s-down] 'move-text-down)
;; Need to test this properly.
;; (when window-system
;; (require 'fill-column-indicator)
;; (add-hook 'after-change-major-mode-hook 'fci-mode)
;; (define-globalized-minor-mode global-fci-mode fci-mode
;; (lambda () (fci-mode 1)))
;; (global-fci-mode 1)
;; (setq fci-rule-color "red")
;; )
(autoload 'expand-region "expand-region" nil t)
(autoload 'contract-region "expand-region" nil t)
(global-set-key (kbd "M-8") 'er/expand-region)
(global-set-key (kbd "M-7") 'er/contract-region)
(require 'ace-jump-mode)
(define-key global-map (kbd "C-.") 'ace-jump-mode)
(require 'fastnav)
(global-set-key "\M-z" 'fastnav-zap-up-to-char-forward)
(global-set-key "\M-Z" 'fastnav-zap-up-to-char-backward)
(global-set-key "\M-s" 'fastnav-jump-to-char-forward)
(global-set-key "\M-S" 'fastnav-jump-to-char-backward)
(global-set-key "\M-r" 'fastnav-replace-char-forward)
(global-set-key "\M-R" 'fastnav-replace-char-backward)
(global-set-key "\M-i" 'fastnav-insert-at-char-forward)
(global-set-key "\M-I" 'fastnav-insert-at-char-backward)
(global-set-key "\M-j" 'fastnav-execute-at-char-forward)
(global-set-key "\M-J" 'fastnav-execute-at-char-backward)
(global-set-key "\M-k" 'fastnav-delete-char-forward)
(global-set-key "\M-K" 'fastnav-delete-char-backward)
(global-set-key "\M-m" 'fastnav-mark-to-char-forward)
(global-set-key "\M-M" 'fastnav-mark-to-char-backward)
(global-set-key "\M-p" 'fastnav-sprint-forward)
(global-set-key "\M-P" 'fastnav-sprint-backward)
;; Find things fast.
(defvar ftf-filetypes
'("*")
"A list of filetype patterns that grepsource will use.")
(autoload 'ftf-find-file "find-things-fast" nil t)
(autoload 'ftf-grepsource "find-things-fast" nil t)
(global-set-key (kbd "C-x f") 'ftf-find-file)
(global-set-key (kbd "<f6>") 'ftf-grepsource)
;; Highlight current symbol.
(require 'highlight-symbol)
(defun goog/config/highlight-symbol-mode/setup ()
(when window-system
(highlight-symbol-mode)
(setq highlight-symbol-idle-delay 0.1)
))
(add-hook 'text-mode-hook 'goog/config/highlight-symbol-mode/setup)
(add-hook 'prog-mode-hook 'goog/config/highlight-symbol-mode/setup)
;; Why does js2-mode not inherit from prog-mode?
(add-hook 'js2-mode-hook 'goog/config/highlight-symbol-mode/setup)
;; global diff highlight mode.
(global-diff-hl-mode)
;; ----------------------------------------------------------------------
;; Mark and edit multiple regions.
;; ----------------------------------------------------------------------
(require 'iedit)
(put 'narrow-to-region 'disabled nil) ;; Allow narrowing to work.
(require 'multiple-cursors)
;; From active region to multiple cursors:
(global-set-key (kbd "C-, C-l") 'mc/edit-lines)
(global-set-key (kbd "C-, C-e") 'mc/edit-ends-of-lines)
(global-set-key (kbd "C-, C-a") 'mc/edit-beginnings-of-lines)
;; Mark more like this.
(global-set-key (kbd "C-, C-;") 'mc/mark-all-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-, C-h") 'mc/mark-all-symbols-like-this)
(global-set-key (kbd "C-, C-d") 'mc/mark-all-symbols-like-this-in-defun)
(global-set-key (kbd "C-, C-,") 'mc/mark-all-like-this-dwim)
(global-set-key (kbd "C-, C-r") 'mc/mark-all-in-region)
(require 'sgml-mode)
(autoload 'rename-sgml-tag "rename-sgml-tag" nil t)
(define-key sgml-mode-map (kbd "C-c C-r") 'rename-sgml-tag)
;; ======================================================================
;; Auto-complete and snippets.
;; ======================================================================
(require 'dabbrev)
(require 'yasnippet)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets" ;; Our snippets.
;; Add more paths here if you like.
))
(yas-global-mode 1) ;; or M-x yas/reload-all to reload yasnippet.
(require 'auto-complete)
(require 'auto-complete-config)
(require 'go-autocomplete)
(ac-config-default)
(setq ac-ignore-case t
ac-use-fuzzy t
ac-auto-start 0
ac-auto-show-menu 0.2
ac-expand-on-auto-complete nil
ac-dwim t)
;; Use TAB to complete, not cycle.
(define-key ac-completing-map "\t" 'ac-complete)
;; Disable RET completion.
(define-key ac-completing-map "\r" nil)
(define-key ac-completing-map [return] nil)
(setq ac-use-menu-map t)
(define-key ac-menu-map (kbd "C-n") 'ac-next)
(define-key ac-menu-map (kbd "C-p") 'ac-previous)
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
;; Set up sources for autocompletion.
(setq-default ac-sources
'(ac-source-abbrev
ac-source-dictionary
ac-source-filename
ac-source-files-in-current-dir
ac-source-imenu
;; ac-source-words-in-all-buffer
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-yasnippet
))
;; (global-auto-complete-mode t)
;; Dirty fix to enable AC everywhere without bothering about the ac-modes list.
(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)
;; ======================================================================
;; Programming-specific.
;; ======================================================================
;; Additional faces.
(defvar font-lock-operator-face 'font-lock-operator-face)
(defface font-lock-operator-face
'((((type tty) (class color)) nil)
(((class color) (background light))
(:foreground "dark red"))
(t nil))
"Used for operators."
:group 'font-lock-faces)
(defvar font-lock-end-statement-face 'font-lock-end-statement-face)
(defface font-lock-end-statement-face
'((((type tty) (class color)) nil)
(((class color) (background light))
(:foreground "DarkSlateBlue"))
(t nil))
"Used for end statement symbols."
:group 'font-lock-faces)
(defvar font-lock-operator-keywords
'(("\\([][|!.+=&/%*,<>(){}:^~-]+\\)" 1 font-lock-operator-face)
(";" 0 font-lock-end-statement-face)))
;; Automatically set executable permissions on executable script files.
(add-hook 'after-save-hook
'executable-make-buffer-file-executable-if-script-p)
;; Static analysis.
;; (add-hook 'prog-mode-hook 'flycheck-mode)
;; (add-hook 'go-mode-hook 'flycheck-mode)
;; (add-hook 'text-mode-hook 'flycheck-mode)
;; ----------------------------------------------------------------------
;; Define automatic mode detection for file types.
;; ----------------------------------------------------------------------
(setq auto-mode-alist
(append '(
;; YAML.
("\\.yaml$" . yaml-mode)
("\\.yml" . yaml-mode)
;; CSS.
("\\.gss" . css-mode)
;; Sass.
("\\.sass" . sass-mode)
("\\.scss" . sass-mode)
;; HTML.
("\\.tmpl" . html-mode) ;; Server-side template extension.
("\\.mustache" . html-mode) ;; Mustache template extension.
("\\.ng" . html-mode) ;; Angular templates.
;; Dart lang.
("\\.dart$" . dart-mode)
;; Python.
("\\BUCK$" . python-mode)
("\\BUILD$" . python-mode)
("\\SConscript" . python-mode)
("\\SConstruct" . python-mode)
("\\wscript$" . python-mode)
;; JavaScript.
("\\.js$" . js2-mode)
("\\.json$" . js2-mode)
;; Markdown
("\\.text\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode)
("\\.md\\'" . markdown-mode)
;; SQL mode.
;; ("\\.mysql$" . sql-mode)
;; Configuration files.
("\\(?:\\.gitconfig\\|\\.gitmodules\\|config\\)$" . conf-mode)
)
auto-mode-alist))
;; -----------------------------------------------------------------------------
;; Markdown editing.
;; -----------------------------------------------------------------------------
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
;; -----------------------------------------------------------------------------
;; SQL editing.
;; -----------------------------------------------------------------------------
(add-to-list 'auto-mode-alist
'("\\.mysql\\'" . (lambda ()
(sql-mode)
(sql-set-product 'mysql))))
(eval-after-load "sql"
(load-library "sql-indent"))
;; ----------------------------------------------------------------------
;; IELM.
;; ----------------------------------------------------------------------
(defun goog/config/ielm-mode/setup ()
"Configures \\[ielm]."
;; Autocomplete.
(setq ac-sources '(ac-source-functions
ac-source-variables
ac-source-features
ac-source-symbols
ac-source-words-in-same-mode-buffers))
;; (add-to-list 'ac-modes 'inferior-emacs-lisp-mode)
(auto-complete-mode 1))
(add-hook 'ielm-mode-hook 'goog/config/ielm-mode/setup)
;; ----------------------------------------------------------------------
;; sh-mode
;; ----------------------------------------------------------------------
(defun goog/config/sh-mode/setup ()
"Configures `sh-mode'."
;; Coding style.
(setq sh-basic-offset 2
sh-indentation 2))
(add-hook 'sh-mode-hook 'goog/config/sh-mode/setup)
;; ----------------------------------------------------------------------
;; html-mode
;; ----------------------------------------------------------------------
(defun goog/config/html-mode/setup ()
"Configures `html-mode'."
;; Coding style.
(set (make-local-variable 'sgml-basic-offset) 2)
(setq indent-tabs-mode nil) ;; Don't use tabs to indent.
;; Autocompletion.
(zencoding-mode 1))
(add-hook 'html-mode-hook 'goog/config/html-mode/setup)
;; ----------------------------------------------------------------------
;; CSS mode.
;; ----------------------------------------------------------------------
;; (require 'less-css-mode)
(defun goog/config/css-mode/setup ()
"Configures `css-mode'."
;; Coding style.
(setq less-css-indent-level 2
css-indent-offset 2
indent-tabs-mode nil
require-final-newline 't
tab-width 2)
;; Autocomplete.
(setq ac-sources '(
ac-source-words-in-buffer
ac-source-abbrev
ac-source-symbols
ac-source-variables
ac-source-words-in-same-mode-buffers
ac-source-yasnippet
ac-source-css-property
)))
(add-hook 'css-mode-hook 'goog/config/css-mode/setup)
;; (add-hook 'less-css-mode-hook 'goog/config/css-mode/setup)
;; ----------------------------------------------------------------------
;; Dart.
;; ----------------------------------------------------------------------
(autoload 'dart-mode "dart-mode" "Edit Dart code." t)
;; ----------------------------------------------------------------------
;; Go.
;; ----------------------------------------------------------------------
(autoload 'go-mode "go-mode" nil t)
(defun goog/config/go-mode/execute-buffer ()
"Formats, compiles and executes the Go code in the current buffer."
(interactive)
(gofmt)
(save-buffer)
(compile (concat "go run " buffer-file-name)))
(defun goog/config/go-mode/build-buffer ()
"Formats and compiles the Go code in the current buffer."
(interactive)
(gofmt)
(save-buffer)
(compile (concat "go build " buffer-file-name)))
(defun goog/config/go-mode/setup ()
"Configures `go-mode'."
;; Set up coding style.
(setq tab-width 2)
;; Keyboard bindings.
(define-key go-mode-map (kbd "C-c l f") 'gofmt)
(define-key go-mode-map (kbd "C-x C-e") 'goog/config/go-mode/execute-buffer)
(define-key go-mode-map (kbd "C-c C-e") 'goog/config/go-mode/execute-buffer)
(define-key go-mode-map (kbd "C-c C-b") 'goog/config/go-mode/build-buffer) )
(add-hook 'before-save-hook 'gofmt-before-save)
(add-hook 'go-mode-hook 'goog/config/go-mode/setup)
;; ----------------------------------------------------------------------
;; JavaScript
;; ----------------------------------------------------------------------
(autoload 'js2-mode "js2-mode" nil t)
(eval-after-load "js2-mode"
'(progn
(add-hook 'js2-mode-hook 'goog/config/js-mode/setup)
(add-hook 'js2-mode-hook
'(lambda ()
(font-lock-add-keywords nil font-lock-operator-keywords t))
t t)
))
(add-hook 'js-mode-hook 'goog/config/js-mode/setup)
(defun goog/config/js-mode/setup ()
"Configures `js-mode' and `js2-mode'."
;; Coding style.
(setq js-indent-level 2
espresso-indent-level 2
c-basic-offset 2
js2-basic-offset 2
js2-indent-on-enter-key nil
js2-enter-indents-newline t
js2-mode-squeeze-spaces nil
;; js2-bounce-indent-p t