-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.el
224 lines (158 loc) · 7.47 KB
/
user.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
;; Custom user code that doesn't belong to a package goes here
;; Compilation
(setq compilation-read-command nil)
(global-set-key (kbd "<f5>") 'comment-or-uncomment-region)
;; Turn off Bell
(setq ring-bell-function 'ignore)
;; Electric indent
(setq electric-indent-mode t)
(defun disable-electric-indent ()
(set (make-local-variable 'electric-indent-functions)
(list (lambda (arg) 'no-indent))))
;; Auto-scroll and color compilation buffer
(setq compilation-scroll-output t)
(ignore-errors
(require 'ansi-color)
(defun my-colorize-compilation-buffer ()
(when (eq major-mode 'compilation-mode)
(ansi-color-apply-on-region compilation-filter-start (point-max))))
(add-hook 'compilation-filter-hook 'my-colorize-compilation-buffer))
;; Comment or uncomment a marked region or your current line if there is no mark set
(defadvice comment-or-uncomment-region (before slick-comment activate compile)
"When called interactively with no active region, comment a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
(global-set-key (kbd "C-c c") 'comment-or-uncomment-region)
(global-set-key (kbd "s-/") 'comment-or-uncomment-region)
;; Make sure option key only acts as Meta on OSX
(setq mac-right-option-modifier 'nil)
(setq mac-option-key-is-meta t)
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'super) ; sets the Command key as super
;; Font - I like Adobe Source Code Pro (it's free)
(when (display-graphic-p)
(set-face-attribute 'default nil :font "Source Code Pro for Powerline")
(set-face-attribute 'default nil :height 180)) ; 180 means 18pt
;; Vertical ido-prompt
(setq ido-decorations (quote
("\n-> " "" "\n " "\n ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")))
(defun ido-disable-line-truncation ()
(set (make-local-variable 'truncate-lines) nil))
(add-hook 'ido-minibuffer-setup-hook 'ido-disable-line-truncation)
;; Switch windows with SHIFT+arrow keys
(windmove-default-keybindings)
(global-set-key (kbd "<select>") 'windmove-up)
;; Match weird files to the appropriate modes
(setq auto-mode-alist (cons '("Gemfile$" . ruby-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("Gemfile.lock$" . ruby-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("Rakefile$" . ruby-mode) auto-mode-alist))
(add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.apex$" . java-mode))
(add-to-list 'auto-mode-alist '("\\.hamlc$" . haml-mode))
(add-to-list 'auto-mode-alist '("\\.coffee\\.erb$" . coffee-mode))
(add-to-list 'auto-mode-alist '("\\.coffee\\.erb$" . coffee-mode))
(add-to-list 'auto-mode-alist '("\\.hbs$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.jsp$" . web-mode))
;; cursor - like a bar, but it can be a block or something
(setq-default cursor-type 'bar)
;; Shell settings
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell
(replace-regexp-in-string "[[:space:]\n]*$" ""
(shell-command-to-string "$SHELL -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when (equal system-type 'darwin) (set-exec-path-from-shell-PATH))
;; Flyspell
(add-hook 'text-mode-hook (lambda () (flyspell-mode t)))
(require 'cl)
(defun hexcolour-luminance (color)
"Calculate the luminance of a color string (e.g. \"#ffaa00\", \"blue\").
This is 0.3 red + 0.59 green + 0.11 blue and always between 0 and 255."
(let* ((values (x-color-values color))
(r (car values))
(g (cadr values))
(b (caddr values)))
(floor (+ (* .3 r) (* .59 g) (* .11 b)) 256)))
(defun hexcolour-add-to-font-lock ()
(interactive)
(font-lock-add-keywords nil
`((,(concat "#[0-9a-fA-F]\\{3\\}[0-9a-fA-F]\\{3\\}?\\|"
(regexp-opt (x-defined-colors) 'words))
(0 (let ((colour (match-string-no-properties 0)))
(put-text-property
(match-beginning 0) (match-end 0)
'face `((:foreground ,(if (> 128.0 (hexcolour-luminance colour))
"white" "black"))
(:background ,colour)))))))))
(add-hook 'css-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'scss-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'sass-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'less-css-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'sgml-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'nxml-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'haml-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'slim-mode-hook 'hexcolour-add-to-font-lock)
(add-hook 'web-mode-hook 'hexcolour-add-to-font-lock)
(global-set-key (kbd "C-=") 'yas-expand)
(global-set-key (kbd "s-b") 'dumb-jump-go)
(global-set-key (kbd "M-s <left>") 'dumb-jump-back)
;;
;; Start named Emacs server for emacsclient connections
;;
(require 'server)
(unless (server-running-p "emacs-server")
(set 'server-name "emacs-server")
(server-start))
;; Pretty symbols
(add-hook 'prog-mode-hook (lambda ()
(setq prettify-symbols-alist '(("===" . ?≡)
("!==" . ?≢) (">=" . ?≥) ("<=" . ?≤)
("alpha" . ?α) ("beta" . ?β) ("gamma" . ?γ)
("delta" . Δ) ("epsilon" . ?ε) ("zeta" . ?ζ)
("eta" . ?η) ("theta" . ?θ) ("lambda" . ?λ)
("micro" . ?μ) ("pi" . ?π) ("rho" . ?ρ)
("sigma" . ?σ) ("phi" . ?φ) ("omega" . ?Ω)
("sqrt" . ?√) ("sum" . ∑) ("infinity" . ∞)
("Infinity" . ∞) ("=>" . ?⇒) ("->" . ?→)))))
(defconst javascript--prettify-symbols-alist '(("function" . ?λ)
("null" . ?∅)))
(add-hook 'js-mode-hook (lambda ()
(turn-on-prettify-symbols-mode)
(append prettify-symbols-alist javascript--prettify-symbols-alist)))
(add-hook 'js2-mode-hook (lambda ()
(turn-on-prettify-symbols-mode)
(append prettify-symbols-alist javascript--prettify-symbols-alist)))
(global-set-key (kbd "M-x") 'helm-M-x)
;; Scrolling
(setq redisplay-dont-pause t
scroll-margin 1
scroll-step 1
scroll-conservatively 10000
scroll-preserve-screen-position 1)
(setq mouse-wheel-follow-mouse 't)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
(setq-default indent-tabs-mode nil)
(setq tab-width 3)
;; Add NodeJS error format
(require 'compile)
(pushnew '(node "^[ ]+at \\(?:[^\(\n]+ \(\\)?\\([a-zA-Z\.0-9_/-]+\\):\\([0-9]+\\):\\([0-9]+\\)\)?$" 1 2 3)
compilation-error-regexp-alist-alist)
(setq compilation-error-regexp-alist
(cons 'node compilation-error-regexp-alist))
(pushnew '(npm "^[ ]+at \\(?:[^\(\n]+ \(\\)?\\([a-zA-Z\.0-9_/-]+\\):\\([0-9]+\\):\\([0-9]+\\)\)?$" 1 2 3)
compilation-error-regexp-alist-alist)
(setq compilation-error-regexp-alist
(cons 'npm compilation-error-regexp-alist))
;; Scrolling
(setq scroll-margin 1
scroll-conservatively 0
scroll-up-aggressively 0.01
scroll-down-aggressively 0.01)
(setq-default scroll-up-aggressively 0.01
scroll-down-aggressively 0.01)
;; Limit compilation buffer size
(add-hook 'compilation-filter-hook 'comint-truncate-buffer)
(setq comint-buffer-maximum-size 500)