-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.emacs
579 lines (489 loc) · 20 KB
/
.emacs
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
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(require 'package)
;;(add-to-list 'package-archives
;; '("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(add-to-list 'load-path "~/emacs")
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp")
(setq prettier-enabled t)
(condition-case () (require 'local) (error nil))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(company-dabbrev-downcase nil)
'(package-selected-packages
'(magit blacken tide typescript-mode clang-format+ clang-format prettier arduino-mode markdown-preview-mode markdown-mode web-mode rjsx-mode js2-mode paredit cider iedit reason-mode apples-mode ag groovy-mode dockerfile-mode powerline haskell-mode scala-mode graphviz-dot-mode yaml-mode browse-kill-ring default-text-scale ivy projectile flycheck highlight-indent-guides company go-mode go-autocomplete gist exec-path-from-shell string-inflection dumb-jump magit company-statistics))
'(safe-local-variable-values
'((eval if
(buffer-file-name)
(if
(string-match "\\.m?jsx?\\'" buffer-file-name)
(prettier-mode t)))
(eval if
(buffer-file-name)
(if
(string-match
("\\.m?jsx?\\'")
buffer-file-name)
(prettier-mode t)))
(prettier-enabled . t)
(eval prettier-mode t)))
'(warning-suppress-log-types '((comp))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(dolist (package package-selected-packages)
(unless (package-installed-p package)
(package-install package)))
; reason crap
(defun init-reason-merlin ()
(progn
;; Load a single, canonical copy of merlin-mode
(add-to-list 'load-path (expand-file-name "~/emacs/merlin/emacs"))
(require 'reason-mode)
(require 'merlin)
(add-hook 'reason-mode-hook (lambda ()
(add-hook 'before-save-hook 'refmt-before-save)
(merlin-mode)))
(setq merlin-ac-setup t)
(require 'merlin-iedit)
(defun evil-custom-merlin-iedit ()
(interactive)
(if iedit-mode (iedit-mode)
(merlin-iedit-occurrences)))
(define-key merlin-mode-map (kbd "C-c C-e") 'evil-custom-merlin-iedit)
(define-key merlin-mode-map (kbd "C-c M-d") 'merlin-document)))
(defun init-reason ()
;;----------------------------------------------------------------------------
;; Reason setup
;;----------------------------------------------------------------------------
(add-hook 'reason-mode-hook #'subword-mode)
(defun shell-cmd (cmd)
"Returns the stdout output of a shell command or nil if the command returned an error"
(car (ignore-errors (apply 'process-lines (split-string cmd)))))
(setq reason/refmt-bin
(or (shell-cmd "refmt ----where")
(shell-cmd "which refmt")))
(setq reason/merlin-bin
(or (shell-cmd "which ocamlmerlin")
(shell-cmd "ocamlmerlin ----where")))
(setq reason/merlin-base-dir
(when reason/merlin-bin
(replace-regexp-in-string "bin/ocamlmerlin$" "" reason/merlin-bin)))
;; Add npm merlin.el to the emacs load path and tell emacs where to find ocamlmerlin
(when reason/merlin-bin
(setq merlin-command reason/merlin-bin))
(when reason/refmt-bin
(setq refmt-command reason/refmt-bin))
;; We're working on a native project, load and use merlin
(init-reason-merlin))
;(init-reason)
; solarized
(load-theme 'solarized-dark t)
(set-frame-parameter nil 'background-mode 'dark)
(set-terminal-parameter nil 'background-mode 'dark)
; fairyfloss
;(setq custom-theme-load-path '("~/emacs/fairyfloss"))
;(load-theme 'fairyfloss t)
;; jesus christ
(global-unset-key "\M-g")
(global-set-key "\M-g" 'goto-line)
(setq inhibit-startup-screen t) ;; the startup screen is so ugly
(transient-mark-mode 1) ;; works like zmacs-regions. 1 means turn it on.
(blink-cursor-mode 0) ;; 0 means turn. it. the fuck. off.
(menu-bar-mode 0) ;; ugly and useless
(condition-case () (tool-bar-mode 0) (error nil)) ;; ugly and useless
(condition-case () (set-scroll-bar-mode 'right) (error nil))
(global-font-lock-mode t)
(show-paren-mode t)
(setq autosave-dir "~/.emacs-autosaves/")
(setq backup-dir "~/.emacs-backups/")
(make-directory autosave-dir t)
(make-directory backup-dir t)
(defun auto-save-file-name-p (filename)
(string-match "^#.*#$" (file-name-nondirectory filename)))
(defun make-auto-save-file-name ()
(concat autosave-dir
(if buffer-file-name
(concat "#" (file-name-nondirectory buffer-file-name) "#")
(expand-file-name (concat "#%" (buffer-name) "#")))))
(setq backup-directory-alist (list (cons "." backup-dir)))
(setq make-backup-files t)
(setq backup-by-copying t)
(setq delete-old-versions t)
(setq kept-old-versions 2)
(setq kept-new-versions 10)
(setq version-control t)
(if window-system
(progn
(server-start)
(setq visible-bell t)
(add-to-list 'default-frame-alist '(width . 84))
(add-to-list 'default-frame-alist '(height . 60))
(add-to-list 'default-frame-alist '(cursor-color . "#dc322f")))
(progn
;;this line fixes the solarized background, if it fucks up
;;(custom-set-faces '(default ((t (:background "nil")))))
))
;; for line numbers
(global-display-line-numbers-mode 1)
(ivy-mode)
(ivy-define-key ivy-minibuffer-map (kbd "TAB") #'ivy-partial) ; I don't want pressing tab repeatedly to pick something
(ivy-define-key ivy-minibuffer-map (kbd "<up>") #'ivy-previous-line-or-history)
(global-flycheck-mode)
(setq flycheck-checker-error-threshold 10000)
(setq-default flycheck-disabled-checkers '(python-pylint))
;; web mode stuff
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.m?jsx?$" . web-mode))
(setq web-mode-content-types-alist '(("jsx" . "\\.[m]?js[x]?\\'")))
(defun enable-minor-mode (my-pair)
"Enable minor mode if filename match the regexp. MY-PAIR is a cons cell (regexp . minor-mode)."
(if (buffer-file-name)
(if (string-match (car my-pair) buffer-file-name)
(funcall (cdr my-pair)))))
(add-hook 'web-mode-hook #'(lambda ()
(if prettier-enabled
(enable-minor-mode
'("\\.m?jsx?\\'" . prettier-mode)))))
;; typescript stuff
(defun setup-tide-mode ()
(interactive)
(tide-setup)
(flycheck-mode +1)
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(tide-hl-identifier-mode +1)
(prettier-mode +1)
;; company is an optional dependency. You have to
;; install it separately via package-install
;; `M-x package-install [ret] company`
(company-mode +1))
;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)
;; formats the buffer before saving -- not as good as prettier-mode
;;(add-hook 'before-save-hook 'tide-format-before-save)
(add-hook 'typescript-mode-hook #'setup-tide-mode)
(setq tide-format-options '(:indentSize 2))
;; php mode stuff
(autoload 'php-mode "php-mode" "PHP editing mode." t)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
;; ruby mode stuff
(autoload 'ruby-mode "ruby-mode" "Ruby editing mode." t)
(add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
(add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
;(autoload 'run-ruby "inf-ruby"
; "Run an inferior Ruby process")
;(autoload 'inf-ruby-keys "inf-ruby"
; "Set local key defs for inf-ruby in ruby-mode")
;(add-hook 'ruby-mode-hook
; '(lambda ()
; (inf-ruby-keys)))
;; haskell mode stuff
(autoload 'haskell-mode "haskell-mode" "Haskell editing mode." t)
(add-to-list 'auto-mode-alist '("\\.hs$" . haskell-mode))
(condition-case ()
(load "~/emacs-lisp/haskell-mode/haskell-site-file")
(error nil))
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;;(add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent)
(setq haskell-program-name "/usr/bin/ghci")
;; go mode stuff
(defun my-go-mode-hook ()
;; Call Gofmt before saving
(add-hook 'before-save-hook 'gofmt-before-save)
;; Use goimports instead of go-fmt
(setq gofmt-command "goimports")
;; Godef jump key binding
(local-set-key (kbd "M-.") 'godef-jump)
(local-set-key (kbd "M-*") 'pop-tag-mark)
;; autocomplete
(auto-complete-mode 1)
;; Customize compile command to run go build
(if (not (string-match "go" compile-command))
(set (make-local-variable 'compile-command)
"go build -v && go test -v && go vet")))
(add-hook 'go-mode-hook 'my-go-mode-hook)
(with-eval-after-load 'go-mode
(require 'go-autocomplete)
(require 'auto-complete-config)
(ac-config-default)
(setq ac-auto-start nil)
(global-set-key "\M-/" 'auto-complete))
(add-hook 'after-init-hook 'global-company-mode)
(add-hook 'after-init-hook 'company-statistics-mode)
(global-set-key "\M-/" '(lambda (x)
(interactive "*P")
(if (company-mode-on)
(call-interactively 'company-complete)
(call-interactively 'dabbrev-expand))))
;; yaml-mode stuff
(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
;; python-mode blacken stuff
(setq blacken-only-if-project-is-blackened t)
(add-hook 'python-mode-hook 'blacken-mode)
;; Emacs/W3 Configuration
(condition-case () (require 'w3-auto "w3-auto") (error nil))
;; where is lisp?
;(setq inferior-lisp-program "/usr/bin/clisp")
;; syntax highlighting
;;(setq font-lock-maximum-decoration t)
;(setq-default font-lock-auto-fontify t)
;(setq-default font-lock-use-fonts nil)
;(setq-default font-lock-maximum-decoration t)
;(setq-default font-lock-maximum-size 256000)
;;(setq-default font-lock-mode-enable-list nil)
;;(setq-default font-lock-mode-disable-list nil)
;;(remove-hook 'font-lock-mode-hook 'turn-on-fast-lock)
;;(remove-hook 'font-lock-mode-hook 'turn-on-lazy-shot)
(defun infer-indentation-style ()
;; if our source file uses tabs, we use tabs, if spaces spaces, and if
;; neither, we use the current indent-tabs-mode
(let ((space-count (how-many "^ " (point-min) (point-max)))
(tab-count (how-many "^\t" (point-min) (point-max))))
(if (> space-count tab-count) (setq indent-tabs-mode nil))
(if (> tab-count space-count) (setq indent-tabs-mode t))))
(defun set-tabs (c-like-p)
(if c-like-p
(progn
;; Fucking RMSmacs (by version 21.3, but after 21.1) doesn't
;; fucking make these fucking variables local where it fucking
;; should, so the c-set-style we're about to do below breaks
;; fucking fill-paragraph for fucking all non-c-like modes by
;; fucking default.
(make-local-variable 'paragraph-start)
(make-local-variable 'paragraph-separate)
(c-set-style "linux")))
(setq c-basic-indent 4) ;; xemacs
(setq c-basic-offset 4) ;; emacs
(setq ruby-indent-level 4) ;; ruby-mode is stupid
(setq typescript-indent-level 2) ;; typescript-mode is also stupid
(modify-syntax-entry ?_ "_") ;; don't word-move over underscores
;; tab stuff as recommended by jwz
;; http://www.jwz.org/doc/tabs-vs-spaces.html
(setq tab-width 8)
(setq indent-tabs-mode nil)
;; above defaults are nice, but if the file already has a standard,
;; keep it
(infer-indentation-style)
;; make case labels indent inside switch statements
(c-set-offset 'case-label '+)
;; make the ENTER key indent next line properly
(local-set-key "\C-m" 'newline-and-indent)
;; code colors
(let ((theme-yellow "#b58900")
(theme-orange "#cb4b16")
(theme-red "#dc322f")
(theme-magenta "#d33682")
(theme-violet "#6c71c4")
(theme-blue "#268bd2")
(theme-cyan "#2aa198")
(theme-green "#859900")
(theme-lightblue "#30abe2"))
;(set-face-background 'show-paren-match-face nil)
;(set-face-foreground 'show-paren-match-face nil)
;(set-face-bold 'show-paren-match-face t)
;(set-face-underline 'show-paren-match-face t)
;(set-face-background 'show-paren-mismatch-face "red")
;(set-face-foreground 'show-paren-mismatch-face "black")
;(set-face-bold 'show-paren-mismatch-face t)
;(set-face-underline 'show-paren-mismatch-face t)
;(set-face-background 'isearch "black")
;(set-face-foreground 'isearch theme-lightblue)
;(set-face-background 'isearch-lazy-highlight-face "black")
;(set-face-foreground 'isearch-lazy-highlight-face "orange")
;(set-face-background 'region "black")
;(set-face-foreground 'region theme-lightblue)
;(set-face-foreground 'font-lock-comment-face "#586e75")
;(set-face-foreground 'font-lock-string-face theme-yellow)
;(set-face-foreground 'font-lock-keyword-face theme-violet)
;(set-face-foreground 'font-lock-type-face theme-cyan)
;(set-face-foreground 'font-lock-function-name-face theme-blue)
;(set-face-foreground 'font-lock-variable-name-face theme-blue)
;(set-face-foreground 'font-lock-constant-face theme-yellow)
(if window-system
(progn
(progn
(set-face-foreground 'highlight-indent-guides-character-face "dimgray")
)))))
(defun jwz-untabify ()
(unless indent-tabs-mode
(save-excursion
(goto-char (point-min))
(while (re-search-forward "[ \t]+$" nil t)
(delete-region (match-beginning 0) (match-end 0)))
(goto-char (point-min))
(if (search-forward "\t" nil t)
(untabify (1- (point)) (point-max))))
nil))
; "c-like" modes
(setq c-modes '(java-mode-hook
cperl-mode-hook
c-mode-hook
c++-mode-hook
php-mode-hook
))
; non-"c-like" modes
(setq non-c-modes '(html-mode-hook
lisp-mode-hook
emacs-lisp-mode-hook
haskell-mode-hook
haskell-c-mode-hook
python-mode-hook
ruby-mode-hook
scala-mode-hook
js2-mode-hook
js-mode-hook
web-mode-hook
))
(dolist (mode c-modes nil)
(add-hook mode
'(lambda ()
(make-local-variable 'write-contents-hooks)
(add-hook 'write-contents-hooks 'jwz-untabify)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(set-tabs t)
)))
(dolist (mode non-c-modes nil)
(add-hook mode
'(lambda ()
(make-local-variable 'write-contents-hooks)
(add-hook 'write-contents-hooks 'jwz-untabify)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(set-tabs nil)
)))
(setq minibuffer-max-depth nil)
(line-number-mode t)
(column-number-mode t)
;; "M-x compile" sucks for projects that don't have a makefile in
;; every directory. So, if Makefile doesn't exist in the current
;; default directory, use make-mf to run compile in the default
;; directory of buffer with a magic name (say, "Makefile"). If that
;; buffer doesn't exist, use make-cwd to default to the directory from
;; which emacs was run.
;; (defun make-mf ()
;; (interactive)
;; (with-current-buffer magic-make-buffer-name
;; (compile "make")))
;; (defun make-cwd ()
;; (interactive)
;; (let ((curdir default-directory))
;; (unwind-protect
;; ((progn
;; (cd-absolute command-line-default-directory)
;; (compile "make")))
;; (cd-absolute curdir))))
;; (defun make ()
;; (interactive)
;; (if (or (file-exists-p "Makefile")
;; (file-exists-p "makefile")
;; (file-exists-p "GNUmakefile"))
;; (compile "make")
;; (if (eq nil (get-buffer magic-make-buffer-name))
;; (make-cwd)
;; (make-mf))))
;; (defun make-clean ()
;; (interactive)
;; (with-current-buffer magic-make-buffer-name
;; (compile "make clean")))
;; (setq magic-make-buffer-name "Makefile")
;; (define-key global-map [(control return)] 'make)
; make home and end do what they do on windows
(define-key global-map [find] `beginning-of-line)
(define-key global-map [select] `end-of-line)
(define-key global-map [home] `beginning-of-line)
(define-key global-map [end] `end-of-line)
; I never want help
(global-unset-key "\C-h")
(global-set-key "\C-h" 'backward-delete-char)
; I never want to lose my windows
(condition-case ()
(if window-system
(progn
(global-unset-key "\C-z")
(global-set-key "\C-z" 'undo)
(global-set-key (kbd "s-z") 'undo)))
(error nil))
; font size like a modern mac
(global-set-key (kbd "s-=") 'default-text-scale-increase)
(global-set-key (kbd "s-+") 'default-text-scale-increase)
(global-set-key (kbd "s--") 'default-text-scale-decrease)
(global-set-key (kbd "s-_") 'default-text-scale-decrease)
; paredit from iterm I guess
(add-hook 'paredit-mode-hook (lambda ()
(define-key paredit-mode-map (kbd "M-[ 5 c") 'paredit-forward-slurp-sexp)
(define-key paredit-mode-map (kbd "M-[ 5 d") 'paredit-backward-slurp-sexp)))
; for cvs mode
(setenv "CVS_RSH" "ssh")
; for git
(require 'dominating-file)
;;(add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
;;(setq highlight-indent-guides-method 'character)
;;(setq sql-mysql-program "/usr/local/mysql/bin/mysql")
(defun mechanics ()
(interactive)
(run-scheme
"/usr/local/scmutils/mit-scheme/bin/scheme --library /usr/local/scmutils/mit-scheme/lib"
))
; codepad stuff!
(autoload 'codepad-paste-region "codepad" "Paste region to codepad.org." t)
(autoload 'codepad-paste-buffer "codepad" "Paste buffer to codepad.org." t)
(autoload 'codepad-fetch-code "codepad" "Fetch code from codepad.org." t)
; powerline!
(require 'powerline)
(powerline-default-theme)
;; Enable mouse support
(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))
(if (eq system-type 'dont) ;;'darwin)
(progn
(let ((orig-paste interprogram-paste-function)
(orig-cut interprogram-cut-function))
(defun copy-from-osx ()
(if (executable-find "pbpaste")
(shell-command-to-string "pbpaste")
(orig-paste))
(defun paste-to-osx (text &optional push)
(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 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx))))
; this is slow, use only when needed
;(load-file "~/emacs/graphviz-dot-mode.el")
;; dumb jump mode is smart
(dumb-jump-mode)
(setq dumb-jump-force-searcher 'ag)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
(setq xref-show-definitions-function #'xref-show-definitions-completing-read)
(provide '.emacs)
;;; .emacs ends here