-
Notifications
You must be signed in to change notification settings - Fork 8
/
init.el
336 lines (289 loc) · 11.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
(defvar mswindows-p (string-match "windows" (symbol-name system-type)))
(defvar linux-p (string-match "linux" (symbol-name system-type)))
(cua-mode 1);; cut / copy / paste for noobs
(defun find-project-root ()
(interactive)
(if (ignore-errors (eproject-root))
(eproject-root)
(or (find-git-repo (buffer-file-name)) (file-name-directory (buffer-file-name)))))
(defun find-git-repo (dir)
(if (string= "/" dir) full
nil
(if (file-exists-p (expand-file-name "../.git/" dir))
dir
(find-git-repo (expand-file-name "../" dir)))))
(defun file-path-to-namespace ()
(interactive)
(let (
(root (find-project-root))
(base (file-name-nondirectory buffer-file-name))
)
(substring (replace-regexp-in-string "/" "\." (substring buffer-file-name (length root) (* -1 (length base))) t t) 0 -1)
)
)
(defun csharp-should-method-space-replace ()
"When pressing space while naming a defined method, insert an underscore"
(interactive)
(if (and (looking-back "void Should.*")
(not (and
(looking-at ".*)$")
(looking-back "(.*"))))
(insert "_")
(insert " ")))
(eval-after-load 'csharp-mode
'(progn
(define-key csharp-mode-map (kbd "SPC") 'csharp-should-method-space-replace)))
(require 'package)
(setq package-archives
'(("melpa"
. "http://melpa.org/packages/")))
(package-initialize)
(defun comment-or-uncomment-region-or-line ()
"Comments or uncomments current current line or whole lines in region."
(interactive)
(save-excursion
(let (min max)
(if (region-active-p)
(setq min (region-beginning) max (region-end))
(setq min (point) max (point)))
(comment-or-uncomment-region
(progn (goto-char min) (line-beginning-position))
(progn (goto-char max) (line-end-position))))))
;Recursively add site-lisp to the load path
;Make sure custom stuff goes to the front of the list
(let ((default-directory "~/.emacs.d/site-lisp"))
(let ((old-path (copy-sequence load-path))
(new-load-path nil))
(normal-top-level-add-to-load-path '("."))
(normal-top-level-add-subdirs-to-load-path)
(dolist (var load-path)
(unless (memql var old-path)
(add-to-list 'new-load-path var)
(setq load-path (append new-load-path old-path))))))
(require 'company)
(set-scroll-bar-mode nil)
(tool-bar-mode -1)
(load-theme 'monokai t)
(set-face-attribute 'region nil :background "#555")
(setq company-begin-commands '(self-insert-command))
(setq omnisharp-company-do-template-completion t)
(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-frontends
(quote
(company-pseudo-tooltip-frontend company-echo-metadata-frontend)))
'(company-idle-delay 0.03)
'(company-minimum-prefix-length 1)
'(company-require-match nil)
'(company-show-numbers t)
'(cua-mode t nil (cua-base))
'(helm-ag-insert-at-point (quote word))
'(omnisharp-auto-complete-want-documentation nil)
'(omnisharp-company-sort-results t)
;; '(omnisharp-server-executable-path
;; (quote /Users/jason/\.vim/bundle/Omnisharp/server/OmniSharp/bin/Debug/OmniSharp\.exe))
'(safe-local-variable-values
(quote
((eval when
(fboundp
(quote rainbow-mode))
(rainbow-mode 1)))))
'(savehist-mode t)
'(show-paren-mode t)
'(tool-bar-mode nil))
(when mswindows-p
(set-face-attribute 'default nil
:family "Consolas" :height 100))
(when linux-p
(set-face-attribute 'default nil
:family "Ubuntu Mono" :height 100))
(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.
'(company-tooltip-annotation ((t (:inherit company-tooltip :foreground "yellow")))))
(global-hl-line-mode 1)
;; To customize the background color
(set-face-background 'hl-line "#333")
(setq ring-bell-function 'ignore)
(show-paren-mode t)
(global-set-key (kbd "M-x") 'smex)
;; esc quits
(defun minibuffer-keyboard-quit ()
"Abort recursive edit.
In Delete Selection mode, if the mark is active, just deactivate it;
then it takes a second \\[keyboard-quit] to abort the minibuffer."
(interactive)
(if (and delete-selection-mode transient-mark-mode mark-active)
(setq deactivate-mark t)
(when (get-buffer "*Completions*") (delete-windows-on "*Completions*"))
(abort-recursive-edit)))
(define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-isearch-map [escape] 'minibuffer-keyboard-quit)
(define-key company-mode-map [escape] 'company-abort)
(fset 'yes-or-no-p 'y-or-n-p) ;;stop asking me to type ‘yes’ as a confirmation
(ido-mode t)
(setq ido-enable-flex-matching t)
(setq ido-create-new-buffer 'always)
(defun check-expansion ()
(save-excursion
(if (looking-at "\\_>") t
(backward-char 1)
(if (looking-at "\\.") t
(backward-char 1)
(if (looking-at "->") t nil)))))
(defun do-yas-expand ()
(let ((yas/fallback-behavior 'return-nil))
(yas/expand)))
(defun tab-indent-or-complete ()
(interactive)
(if (minibufferp)
(minibuffer-complete)
(if (or (not yas/minor-mode)
(null (do-yas-expand)))
(if (check-expansion)
(company-complete-common)
(indent-for-tab-command)))))
(define-key company-active-map (kbd "<tab>") 'tab-indent-or-complete)
(setq yas-snippet-dirs
'("~/.emacs.d/yasnippet-csharp"))
(defun dos2unix (buffer)
"Automate M-% C-q C-m RET C-q C-j RET"
(interactive "*b")
(save-excursion
(goto-char (point-min))
(while (search-forward (string ?\C-m) nil t)
(replace-match "" nil t)))
nil
)
(require 'helm-config)
(require 'helm-command)
(require 'helm-elisp)
(require 'helm-misc)
(require 'omnisharp)
(setq compilation-ask-about-save nil)
(global-set-key (kbd "s-o") 'ido-find-file)
;; find current buffer in directory
(global-set-key (kbd "C-M-l") 'neotree-find)
(global-set-key (kbd "<f7>") 'neotree-toggle)
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
(define-key helm-map (kbd "C-j") 'helm-next-line)
(define-key helm-map (kbd "C-k") 'helm-previous-line)
;;VS keys
(define-key global-map (kbd "s-<left>") 'beginning-of-line)
(define-key global-map (kbd "s-<right>") 'end-of-line)
(define-key global-map (kbd "s-<up>") 'scroll-down)
(define-key global-map (kbd "s-<down>") 'scroll-up)
(define-key global-map (kbd "s-f") 'toggle-frame-fullscreen)
(define-key global-map (kbd "S-M-<return>") 'toggle-frame-fullscreen)
(define-key global-map (kbd "C-g") 'goto-line)
(define-key global-map (kbd "C-F") 'helm-projectile-ag)
(global-set-key (kbd "C-x C-f") 'helm-for-files)
(global-set-key (kbd "C-i") 'isearch-forward)
(define-key isearch-mode-map (kbd "<f3>") 'isearch-repeat-forward)
(global-set-key [(control tab)] 'bury-buffer)
(global-set-key [(control shift tab)] 'unbury-buffer)
(global-set-key (kbd "C-M-<left>") 'er/expand-region)
(global-set-key (kbd "C-M-<right>") 'er/contract-region)
;; enable ctrl-s to wrap around seeing as we disabled ctrl-r
(defadvice isearch-repeat (after isearch-no-fail activate)
(unless isearch-success
(ad-disable-advice 'isearch-repeat 'after 'isearch-no-fail)
(ad-activate 'isearch-repeat)
(isearch-repeat (if isearch-forward 'forward))
(ad-enable-advice 'isearch-repeat 'after 'isearch-no-fail)
(ad-activate 'isearch-repeat)))
(require 'key-chord)
(key-chord-mode 1)
(setq key-chord-one-key-delay 0.2)
(setq key-chord-two-keys-delay 0.15)
(define-key global-map (kbd "C-,") 'helm-projectile)
(define-key company-active-map (kbd "C-j") 'company-select-next-or-abort)
(define-key company-active-map (kbd "C-k") 'company-select-previous-or-abort)
;; show tabs and trailing whitespace
(global-whitespace-mode)
(setq whitespace-style '(trailing tabs tab-mark))
(define-key global-map (kbd "s-j") 'ace-jump-mode)
(defun company-complete-selection-insert-key(company-key)
(company-complete-selection)
(insert company-key))
(defun company-complete-selection-insert-key-and-complete(company-key)
(company-complete-selection-insert-key company-key)
(company-complete))
(defun csharp-indent-function-on-closing-brace()
(interactive)
(insert "}")
(c-indent-defun))
;; better than vim-vinegar
(require 'dired)
(global-set-key [M-left] 'elscreen-previous)
(global-set-key [M-right] 'elscreen-next)
;; This is your old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
(setq inhibit-splash-screen t) ;;disable splash screen
(fset 'yes-or-no-p 'y-or-n-p) ;;stop asking me to type ‘yes’ as a confirmation
(show-paren-mode t)
;;Ido mode for file completion:
(ido-mode t)
(setq ido-enable-flex-matching t)
(setq ido-create-new-buffer 'always)
;;ido for better buffer management:
(global-set-key (kbd "C-x C-b") 'ido-switch-buffer)
(global-set-key (kbd "s-b") 'ido-switch-buffer)
;;window movement
(global-set-key (kbd "M-<left>") 'windmove-left)
(global-set-key (kbd "M-<right>") 'windmove-right)
(global-set-key (kbd "M-<down>") 'windmove-down)
(global-set-key (kbd "M-<up>") 'windmove-up)
(autoload 'ibuffer "ibuffer" "List buffers." t)
;; (setq backup-directory-alist
;; `((".*" . ,temporary-file-directory)))
;; (setq auto-save-file-name-transforms
;; `((".*" ,temporary-file-directory t)))
;; disable auto-save and auto-backup
(setq auto-save-default nil)
(setq make-backup-files nil)
(setq create-lockfiles nil)
(require 'highlight-parentheses)
(define-globalized-minor-mode global-highlight-parentheses-mode
highlight-parentheses-mode
(lambda ()
(highlight-parentheses-mode t)))
(global-highlight-parentheses-mode t)
(setq ring-bell-function 'ignore)
(projectile-global-mode)
(setq projectile-indexing-method 'alien)
(setq c-basic-offset 4) ; indents 4 chars
(setq tab-width 4) ; and 4 char wide for TAB
(setq indent-tabs-mode nil) ; And force use of spaces
(defun load-directory (directory)
"Load recursively all `.el' files in DIRECTORY."
(dolist (element (directory-files-and-attributes directory nil nil nil))
(let* ((path (car element))
(fullpath (concat directory "/" path))
(isdir (car (cdr element)))
(ignore-dir (or (string= path ".") (string= path ".."))))
(cond
((and (eq isdir t) (not ignore-dir))
(load-directory fullpath))
((and (eq isdir nil) (string= (substring path -3) ".el"))
(load (file-name-sans-extension fullpath)))))))
(load-directory "~/.emacs.d/config")
;; (add-hook 'term-mode-hook 'evil-emacs-state)
(defun my-term-use-utf8 ()
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))
(add-hook 'term-exec-hook 'my-term-use-utf8)
(defun my-term-hook ()
(goto-address-mode)
(define-key term-raw-map "\C-y" 'my-term-paste))
(add-hook 'term-mode-hook 'my-term-hook)
(setq system-uses-terminfo nil)