-
Notifications
You must be signed in to change notification settings - Fork 1
/
.emacs
419 lines (346 loc) · 11.8 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
;; No splash screen please ... jeez
(setq inhibit-startup-message t)
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;; enable recentf
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key (kbd "H-r") 'recentf-open-files)
(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)
(setq ns-function-modifier 'hyper)
;; Hyper-F for toggling fullscreen
(global-set-key (kbd "H-f") 'ns-toggle-fullscreen)
(setq ispell-program-name "/usr/local/bin/aspell")
(setq ispell-list-command "list")
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
(setq ido-use-virtual-buffers t)
(add-to-list 'load-path (expand-file-name "~/.emacs.d/elpa/"))
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
;; add powerline for
(powerline-default)
;; hippie-exand
(global-set-key "\257" (quote hippie-expand)) ;; M-/
;; ace-jump
(global-set-key " " (quote ace-jump-mode)) ;; C-c <space>
;; fix C-= for expand-region
(global-set-key (kbd "C-=") 'er/expand-region)
(require 'rst)
(define-key rst-mode-map (kbd "C-=") 'er/expand-region)
(require 'ahg)
(setq ahg-hg-command "/usr/local/bin/hg")
;; Quick and dirty path fix for OS X
(if (string-equal "darwin" (symbol-name system-type))
(setenv "PATH" (concat "/usr/texbin:/usr/local/bin:/usr/local/sbin:" (getenv "PATH"))))
;; key bindings for multiple cursors
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
;; ediff config
(load-library "ediff")
(add-hook 'ediff-before-setup-hook 'new-frame)
(add-hook 'ediff-quit-hook 'delete-frame)
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-horizontally)
(global-set-key (kbd "C-x v =") 'vc-ediff) ;; rebind C-x v =
(require 'rect-mark)
(global-set-key (kbd "C-x r C-SPC") 'rm-set-mark)
(global-set-key (kbd "C-w")
'(lambda(b e) (interactive "r")
(if rm-mark-active
(rm-kill-region b e) (kill-region b e))))
(global-set-key (kbd "M-w")
'(lambda(b e) (interactive "r")
(if rm-mark-active
(rm-kill-ring-save b e) (kill-ring-save b e))))
(global-set-key (kbd "C-x C-x")
'(lambda(&optional p) (interactive "p")
(if rm-mark-active
(rm-exchange-point-and-mark p) (exchange-point-and-mark p))))
;; fixar med path
(add-to-list 'exec-path "/usr/local/bin")
;; Write backup files to own directory
(setq backup-directory-alist
`(("." . ,(expand-file-name
(concat user-emacs-directory "backup-files")))))
;; Make backups of files, even when they're in version control
(setq vc-make-backup-files t)
;; Gör så att C-d dödar shell och en till dödar buffer
(defun comint-delchar-or-eof-or-kill-buffer (arg)
(interactive "p")
(if (null (get-buffer-process (current-buffer)))
(kill-buffer)
(comint-delchar-or-maybe-eof arg)))
(add-hook 'shell-mode-hook
(lambda ()
(define-key shell-mode-map
(kbd "C-d") 'comint-delchar-or-eof-or-kill-buffer)))
;; 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)
;; aktivera line numbers
;;(global-linum-mode t)
;; highligt current line globally
(global-hl-line-mode t)
(global-set-key (kbd "C-x g") 'webjump)
;; Add Urban Dictionary to webjump
(eval-after-load "webjump"
'(add-to-list 'webjump-sites
'(
("Urban Dictionary" .
[simple-query
"www.urbandictionary.com"
"http://www.urbandictionary.com/define.php?term="
""])
("Stack Overflow" .
[simple-query
"stackoverflow.com"
"https://stackoverflow.com/search?q"
""])
("Programmers" .
[simple-query
"programmers.stackexchange.com"
"http://programmers.stackexchange.com/search?q"
""])
("Super User" .
[simple-query
"superuser.com"
"https://superuser.com/search?q"
""])
("Serverfault" .
[simple-query
"serverfault.com"
"https://serverfault.com/search?q"
""])
("Ask Ubuntu" .
[simple-query
"askubuntu.com"
"http://askubuntu.com/search?q"
""])
("Unix & Linux" .
[simple-query
"unix.stackexchange.com"
"https://unix.stackexchange.com/search?q"
""])
("Programmers" .
[simple-query
"programmers.stackexchange.com"
"https://programmers.stackexchange.com/search?q"
""])
("IT Security" .
[simple-query
"security.stackexchange.com"
"http://security.stackexchange.com/search?q"
""])
("Nullege" .
[simple-query
"nullege.com"
"http://nullege.com/codes/search?cq"
""])
("Google" .
[simple-query
"google.com"
"https://encrypted.google.com/#q="
""])
("Google Images" .
[simple-query
"google.com"
"https://encrypted.google.com/images?q"
""])
("Google Videos" .
[simple-query
"google.com"
"https://encrypted.google.com/search?tbs=vid%3A1&q"
""])
("Google Translate En-Sv" .
[simple-query
"google.com"
"http://translate.google.com/#en|sv|"
""])
("Google Translate Sv-En" .
[simple-query
"google.com"
"http://translate.google.com/#sv|en|"
""])
; Default to translating anything to Swedish
("Google Translate" .
[simple-query
"google.com"
"http://translate.google.com/#auto|sv|"
""])
("Google Translate Auto-Sv" .
[simple-query
"google.com"
"http://translate.google.com/#auto|sv|"
""])
("Google Translate Auto-En" .
[simple-query
"google.com"
"http://translate.google.com/#auto|en|"
""])
("Urban Dictionary" .
[simple-query
"www.urbandictionary.com"
"http://www.urbandictionary.com/define.php?term"
""])
)
)
)
;; Save point position between sessions
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (expand-file-name ".places" user-emacs-directory))
;; Döp om fil och buffer
(defun rename-current-buffer-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
(global-set-key (kbd "C-x C-r") 'rename-current-buffer-file)
(defun dired-do-ispell (&optional arg)
(interactive "P")
(dolist (file (dired-get-marked-files
nil arg
#'(lambda (f)
(not (file-directory-p f)))))
(save-window-excursion
(with-current-buffer (find-file file)
(ispell-buffer)))
(message nil)))
;;(load-file "/Users/malo/Downloads/gabrielelanaro-emacs-for-python-ac1b31e/epy-init.el")
;; org-mode fixes
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c c") 'org-capture)
(global-set-key (kbd "C-c l") 'org-store-link)
(setq org-default-notes-file "~/Dropbox/notes.org")
(setq org-refile-targets '((nil :maxlevel . 9)
(org-agenda-files :maxlevel . 3)
))
(setq org-log-done 'time)
(setq org-todo-keywords
'((sequence "TODO(t)" "STARTED(s)" "WAIT(w)" "|" "DONE(d)" "CANCELLED(c)")))
(setq org-todo-keyword-faces
'(("TODO" . org-warning) ("STARTED" . "yellow") ("WAIT" . "orange") ("DONE" . org-done) ("CANCELLED" . "blue")))
(setq org-mobile-inbox-for-pull "~/Dropbox/flagged.org")
(setq org-mobile-directory "~/Dropbox/Apps/MobileOrg")
;; ace-jump i org-mode
(eval-after-load "org"
'(define-key org-mode-map "\C-c " 'nil)) ; unmap key, was org-table-blank-field
;; skeleton does not work well in table-mode, deactivate
;; hippie expand fucks up too
;; also, don't be messin' with my captialize-word shortcut
(global-set-key (kbd "M-c") 'capitalize-word)
;; rgrep och snabbtangent för next- och previous-error
(global-set-key (kbd "<f9>") 'next-error)
(global-set-key (kbd "S-<f9>") 'previous-error)
(global-set-key (kbd "C-<f9>") 'rgrep)
;; fixa magit
;; full screen magit-status
(defadvice magit-status (around magit-fullscreen activate)
(window-configuration-to-register :magit-fullscreen)
ad-do-it
(delete-other-windows))
(defun magit-quit-session ()
"Restores the previous window configuration and kills the magit buffer"
(interactive)
(kill-buffer)
(jump-to-register :magit-fullscreen))
(require 'magit)
(define-key magit-status-mode-map (kbd "q") 'magit-quit-session)
(global-set-key (kbd "H-g") 'magit-status)
;; Loccur - dölj alla rader som inte matchar...
(require 'loccur)
(global-set-key (kbd "M-s l") 'loccur)
;; yasnippets
(require 'yasnippet)
(setq yas/root-directory (concat user-emacs-directory "mysnippets"))
(yas/load-directory yas/root-directory)
;; org-present
;;(add-to-list 'load-path "~/.emacs.d/org-present")
;;(autoload 'org-present "org-present" nil t)
;;(add-hook 'org-present-mode-hook
;; (lambda ()
;; (org-present-big)
;; (org-display-inline-images)))
;;(add-hook 'org-present-mode-quit-hook
;; (lambda ()
;; (org-present-small)
;; (org-remove-inline-images)))
;; gnuplot
(require 'gnuplot)
(setq gnuplot-program "/usr/local/bin/gnuplot")
(setq auto-mode-alist
(append '(("\\.\\(gp\\|gnuplot\\)$" . gnuplot-mode)) auto-mode-alist))
;;(require 'ox-reveal)
;;(setq org-reveal-root "file:///Users/malo/code/reveal.js")
;;(add-to-list 'load-path "~/.emacs.d/ox-rst")
;;(require 'ox-rst)
;; open file with
(defun prelude-open-with ()
"Simple function that allows us to open the underlying
file of a buffer in an external program."
(interactive)
(when buffer-file-name
(shell-command (concat
(if (eq system-type 'darwin)
"open"
(read-shell-command "Open current file with: "))
" '"
buffer-file-name
"'"))))
(global-set-key (kbd "C-c o") 'prelude-open-with)
(defun split-string-chars (string chars &optional omit-nulls)
(let ((separators (make-hash-table))
(last 0)
current
result)
(dolist (c chars) (setf (gethash c separators) t))
(dotimes (i (length string)
(progn
(when (< last i)
(push (substring string last i) result))
(reverse result)))
(setq current (aref string i))
(when (gethash current separators)
(when (or (and (not omit-nulls) (= (1+ last) i))
(/= last i))
(push (substring string last i) result))
(setq last (1+ i))))))
(defun unique-lines (start end)
"This will remove all duplicating lines in the region.
Note empty lines count as duplicates of the empy line! All empy lines are
removed sans the first one, which may be confusing!"
(interactive "r")
(let ((hash (make-hash-table :test #'equal)) (i -1))
(dolist (s (split-string-chars
(buffer-substring-no-properties start end) '(?\n) t)
(let ((lines (make-vector (1+ i) nil)))
(maphash
(lambda (key value) (setf (aref lines value) key))
hash)
(kill-region start end)
(insert (mapconcat #'identity lines "\n"))))
(unless (gethash s hash)
(setf (gethash s hash) (incf i))))))
;; fixa en custom-fil, måste ligga nederst
(setq custom-file (concat user-emacs-directory "custom.el"))
(load custom-file 'noerror)