-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
509 lines (385 loc) · 13.8 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
;; package.el
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
;; power-line
(powerline-center-theme)
;; yascroll
(global-yascroll-bar-mode)
;; rainbow-delimeter
(rainbow-delimiters-mode t)
;; fix the mac PATH variable
(defun ome-set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "zsh -i -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when (eq system-type 'darwin)
(when window-system (ome-set-exec-path-from-shell-PATH)))
;; goto-last-change
(global-set-key (kbd "C-x C-\\") 'goto-last-change)
;; helm
(require 'helm-config)
(setq helm-input-idle-delay 0.2)
(helm-mode t)
(global-set-key (kbd "C-c <SPC>") 'helm-all-mark-rings)
(global-set-key (kbd "C-x c o") 'helm-occur)
(global-set-key (kbd "C-x C-/") 'helm-find)
(global-set-key (kbd "M-g s") 'helm-do-grep)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "C-x C-b") 'helm-buffers-list)
(global-set-key (kbd "C-x C-r") 'helm-recentf)
;; expand-region
(global-set-key (kbd "M-i") 'er/expand-region)
(global-set-key (kbd "M-S-<up>") 'er/mark-inside-quotes)
(global-set-key (kbd "M-S-<down>") 'er/mark-inside-pairs)
;; undo-tree
(global-undo-tree-mode)
;; auto-complete
(require 'auto-complete-config)
(ac-config-default)
(global-auto-complete-mode t)
(setq ac-dwim t)
(setq ac-use-menu-map t)
(setq ac-quick-help-delay 1)
(setq ac-quick-help-height 60)
(setq ac-auto-start 2)
(setq ac-candidate-menu-min 2)
;; git-gutter
(setq git-gutter:window-width 2)
(global-git-gutter-mode t)
(setq git-gutter:lighter " G-+")
(setq git-gutter:modified-sign "~ ")
(setq git-gutter:added-sign "+ ")
(setq git-gutter:deleted-sign "- ")
(setq git-gutter:unchanged-sign nil)
(global-set-key (kbd "C-c n")
'git-gutter:next-hunk)
(global-set-key (kbd "C-c l")
'git-gutter:previous-hunk)
(global-set-key (kbd "C-c h")
'git-gutter:stage-hunk)
;; window-number
(autoload 'window-number-mode "window-number" t)
(window-number-mode 1)
(autoload 'window-number-meta-mode
"window-number" t)
(window-number-meta-mode 1)
;; elisp
(defun ome-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"))))))
(add-hook 'emacs-lisp-mode-hook 'ome-remove-elc-on-save)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
; (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
; (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
;; elisp-slime-nav
(add-hook 'emacs-lisp-mode-hook 'turn-on-elisp-slime-nav-mode)
; ;; ace-jump-mode
(require 'ace-jump-mode)
(setq ace-jump-mode-submode-list
'(ace-jump-char-mode
ace-jump-line-mode))
(global-set-key (kbd "C-o") 'ace-jump-mode)
(ace-jump-mode-enable-mark-sync)
;;; Customized configuration
;; mac specific settings
(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
;; key-bindings
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
(global-set-key (kbd "C-c o") 'occur)
(global-set-key (kbd "M-h") 'help-command)
(global-set-key (kbd "M-/") 'comment-or-uncomment-region)
(define-key lisp-mode-shared-map (kbd "RET") 'reindent-then-newline-and-indent)
; (global-set-key (kbd "C-c b") 'winner-undo)
; (global-set-key (kbd "C-c f") 'winner-redo)
; ;;; language specific setting
;;emacs-lisp shortcuts
(global-set-key (kbd "C-c C-b") 'eval-buffer)
(global-set-key (kbd "C-c C-p") 'eval-print-last-sexp)
(global-set-key (kbd "C-c C-r") 'eval-region)
(global-set-key (kbd "C-j") 'eval-last-sexp)
;;fast vertical naviation
(global-set-key (kbd "M-U") (lambda () (interactive) (forward-line -10)))
(global-set-key (kbd "M-D") (lambda () (interactive) (forward-line 10)))
(global-set-key (kbd "M-p") 'outline-previous-visible-heading)
(global-set-key (kbd "M-n") 'outline-next-visible-heading)
;; Dired
(defun dired-back-to-top ()
(interactive)
(beginning-of-buffer)
(dired-next-line 4))
(define-key dired-mode-map
(vector 'remap 'beginning-of-buffer) 'dired-back-to-top)
(defun dired-jump-to-bottom ()
(interactive)
(end-of-buffer)
(dired-next-line -1))
(define-key dired-mode-map
(vector 'remap 'end-of-buffer) 'dired-jump-to-bottom)
(global-set-key (kbd "M-j")
(lambda ()
(interactive)
(join-line -1)))
(defun move-line-down ()
(interactive)
(let ((col (current-column)))
(save-excursion
(forward-line)
(transpose-lines 1))
(forward-line)
(move-to-column col)))
(defun move-line-up ()
(interactive)
(let ((col (current-column)))
(save-excursion
(forward-line)
(transpose-lines -1))
(move-to-column col)))
(global-set-key (kbd "<C-M-down>") 'move-line-down)
(global-set-key (kbd "<C-M-up>") 'move-line-up)
;;mimic vim
;;Turn off cua mode first
(defun open-line-below ()
(interactive)
(end-of-line)
(newline)
(indent-for-tab-command))
(defun open-line-above ()
(interactive)
(beginning-of-line)
(newline)
(forward-line -1)
(indent-for-tab-command))
(global-set-key (kbd "<C-return>") 'open-line-below)
(global-set-key (kbd "<C-S-return>") 'open-line-above)
(defun live-show-messages ()
(interactive)
(popwin:display-buffer "*Messages*"))
(global-set-key (kbd "C-c s m") 'live-show-messages)
; ;;scroll other window
(global-set-key (kbd "C-M-]") 'scroll-other-window)
(global-set-key (kbd "C-M-[") 'scroll-other-window-down)
; (global-set-key (kbd "M-'") 'repeat)
; (global-set-key (kbd "C-x M-f") 'ido-find-file-other-window)
; (global-set-key (kbd "C-c y") 'bury-buffer)
; (global-set-key (kbd "C-x C-b") 'ibuffer)
(defun live-lisp-describe-thing-at-point ()
"Show the documentation of the Elisp function and variable near point.
This checks in turn:
-- for a function name where point is
-- for a variable name where point is
-- for a surrounding function call"
(interactive)
(let (sym)
;; sigh, function-at-point is too clever. we want only the first half.
(cond ((setq sym (ignore-errors
(with-syntax-table emacs-lisp-mode-syntax-table
(save-excursion
(or (not (zerop (skip-syntax-backward "_w")))
(eq (char-syntax (char-after (point))) ?w)
(eq (char-syntax (char-after (point))) ?_)
(forward-sexp -1))
(skip-chars-forward "`'")
(let ((obj (read (current-buffer))))
(and (symbolp obj) (fboundp obj) obj))))))
(describe-function sym))
((setq sym (variable-at-point)) (describe-variable sym)))))
(define-key lisp-mode-shared-map (kbd "M-RET") 'live-lisp-describe-thing-at-point)
; ;;imenu
; (global-set-key (kbd "C-.") 'imenu)
; ;;bookmark
; (global-set-key (kbd "<f8>") 'bookmark-set)
; (global-set-key (kbd "<f9>") 'bookmark-jump)
; (global-set-key (kbd "<f7>") 'bookmark-bmenu-list)
; ;;idomenu
; (global-set-key (kbd "C-c M-b") 'find-file-at-point)
; ;;candidates
; (global-set-key (kbd "C-c j p") 'quick-jump-go-back)
; (global-set-key (kbd "C-c j b") 'quick-jump-go-back)
; (global-set-key (kbd "C-c j m") 'quick-jump-push-marker)
; (global-set-key (kbd "C-c j n") 'quick-jump-go-forward)
; (global-set-key (kbd "C-c j f") 'quick-jump-go-forward)
; (global-set-key (kbd "C-c j c") 'quick-jump-clear-all-marker)
; (global-set-key (kbd "C-c d f") 'diff-buffer-with-file)
;; misc
(setq-default save-place t)
(setq save-place-file (concat user-emacs-directory ".saved-places"))
(require 'saveplace)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
(require 'uniquify)
;; use aspell instead of ispell
(setq ispell-program-name "aspell"
ispell-extra-args '("--sug-mode=ultra"))
(set-language-environment "UTF-8")
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(fset 'yes-or-no-p 'y-or-n-p)
(setq require-final-newline t)
(setq next-line-add-newlines nil)
(setq ring-bell-function 'ignore)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; enable to support navigate in camelCase words
(global-subword-mode t)
; ;; hide startup splash screen
; (setq inhibit-startup-screen t)
(setq-default major-mode 'text-mode)
;; Auto refresh buffers
(global-auto-revert-mode 1)
;; Also auto refresh dired, but be quiet about it
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)
;;; GUI
;; popwin
(require 'popwin)
(popwin-mode 1)
(push '("*Messages*" :noselect t :height 30)
popwin:special-display-config)
(push '("*Buffer List*")
popwin:special-display-config)
;; remove useless gui
(dolist (mode '(tool-bar-mode scroll-bar-mode))
(when (fboundp mode) (funcall mode -1)))
;; show parenthesis match
(show-paren-mode 1)
(setq show-paren-style 'parenthesis)
;; auto-fill mode
(setq-default fill-column 79)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'prog-mode-hook 'turn-on-auto-fill)
;; font
(if (member "Monaco" (font-family-list))
(set-face-attribute
'default nil :font "Monaco 12"))
;;;; Mode hooks
;; outline-mode
(add-hook 'prog-mode-hook
(lambda ()
(outline-minor-mode t)))
; ;; winner undo and redo
; (when (fboundp 'winner-mode)
; (winner-mode 1))
;; primitive backup-dir
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
; ;; eshell
; (add-hook 'eshell-mode-hook
; (lambda ()
; (add-to-list 'ac-sources 'ac-source-pcomplete)))
; (add-to-list 'ac-modes 'eshell-mode)
; (add-hook 'eshell-mode-hook 'turn-on-eldoc-mode)
; (add-hook 'eshell-mode-hook 'ac-emacs-lisp-mode-setup)
; ;;; shell-mode settings
; (unless (eq system-type 'windows-nt)
; (setq explicit-shell-file-name "/bin/bash")
; (setq shell-file-name "/bin/bash"))
; ;; always insert at the bottom
; (setq comint-scroll-to-bottom-on-input t)
; (setq comint-input-ignoredups t)
; ; what to run when press enter on a line above the current prompt
; (setq comint-get-old-input (lambda () ""))
; ;; set lang to enable Chinese display in shell-mode
; (setenv "LANG" "en_US.UTF-8")
(setq recentf-save-file (concat user-emacs-directory ".recentf"))
(recentf-mode t)
(setq recentf-max-saved-items 50)
(setq sgml-basic-offset 4)
; ;;; flycheck
; (defun flycheck-setup ()
; (eval-after-load 'flycheck
; '(setq flycheck-checkers (delq 'emacs-lisp-checkdoc flycheck-checkers)))
; (add-hook 'prog-mode-hook 'flycheck-mode))
; (flycheck-setup)
; (require 'dired-x)
; (setq-default dired-omit-files-p t)
; (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
(defun backward-kill-line (arg)
"Kill ARG lines backward."
(interactive "p")
(kill-line (- 1 arg)))
(global-set-key (kbd "M-k") 'backward-kill-line)
(setq ad-redefinition-action 'accept)
(require 'moe-theme)
(load-theme 'moe-dark t)
(require 'ac-geiser)
(add-hook 'geiser-mode-hook 'ac-geiser-setup)
(add-hook 'geiser-repl-mode-hook 'ac-geiser-setup)
(eval-after-load "auto-complete"
'(add-to-list 'ac-modes 'geiser-repl-mode))
(setq blink-cursor-blinks 5)
(blink-cursor-mode 1)
(setq-default cursor-type 'bar)
(dolist (hook '(text-mode-hook))
(add-hook hook (lambda () (flyspell-mode 1))))
(global-set-key (kbd "<f8>") 'ispell-word)
(defun flyspell-check-next-highlighted-word ()
"Custom function to spell check next highlighted word"
(interactive)
(flyspell-goto-next-error)
(ispell-word))
(global-set-key (kbd "M-<f8>") 'flyspell-check-next-highlighted-word)
;;;; Scheme config
(autoload 'paredit-mode "paredit"
"Minor mode for pseudo-structurally editing Lisp code."
t)
(require 'cmuscheme)
(setq scheme-program-name "scheme")
(defun scheme-proc ()
"Return the current Scheme process, starting one if necessary."
(unless (and scheme-buffer
(get-buffer scheme-buffer)
(comint-check-proc scheme-buffer))
(save-window-excursion
(run-scheme scheme-program-name)))
(or (scheme-get-process)
(error "No current process. See variable `scheme-buffer'")))
(defun scheme-split-window ()
(cond
((= 1 (count-windows))
(delete-other-windows)
(split-window-vertically (floor (* 0.68 (window-height))))
(other-window 1)
(switch-to-buffer "*scheme*")
(other-window 1))
((not (find "*scheme*"
(mapcar (lambda (w) (buffer-name (window-buffer w)))
(window-list))
:test 'equal))
(other-window 1)
(switch-to-buffer "*scheme*")
(other-window -1))))
(defun scheme-send-last-sexp-split-window ()
(interactive)
(scheme-split-window)
(scheme-send-last-sexp))
(defun scheme-send-definition-split-window ()
(interactive)
(scheme-split-window)
(scheme-send-definition))
(add-hook 'scheme-mode-hook
(lambda ()
(paredit-mode 1)
(define-key scheme-mode-map (kbd "<f5>") 'scheme-send-last-sexp-split-window)
(define-key scheme-mode-map (kbd "<f6>") 'scheme-send-definition-split-window)))
(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.
'(helm-M-x-fuzzy-match t)
'(helm-buffers-fuzzy-matching t)
'(helm-recentf-fuzzy-match nil))