-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
executable file
·335 lines (284 loc) · 10.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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customised emacs config ;;
;; Author: Andrew Higginson <me@drewzh.com> ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Turn on debugging (comment this out for normal use)
;(setq debug-on-error t)
;; remove top bars
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; add directories to load path ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path user-emacs-directory)
(let ((default-directory "~/.emacs.d/elpa/"))
(setq load-path
(append
(let ((load-path (copy-sequence load-path))) ;; Shadow
(append
(copy-sequence (normal-top-level-add-to-load-path '(".")))
(normal-top-level-add-subdirs-to-load-path)))
load-path)))
;;;;;;;;;;;;;;;;;;;;
;; package system ;;
;;;;;;;;;;;;;;;;;;;;
(require 'package)
(dolist (source '(("marmalade" . "http://marmalade-repo.org/packages/")
("elpa" . "http://tromey.com/elpa/")))
(add-to-list 'package-archives source t))
(package-initialize)
;;;;;;;;;;;;;;;;;
;; color theme ;;
;;;;;;;;;;;;;;;;;
(when window-system
(load "color-theme")
;; (load "color-theme-twilight")
(require 'color-theme-solarized)
(setq color-theme-is-global t)
(color-theme-solarized-dark))
;;;;;;;;;;;;;;;;;;;
;; auto complete ;;
;;;;;;;;;;;;;;;;;;;
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
(setq ac-auto-start t)
(setq ac-delay 0)
(setq ac-auto-show-menu t)
(setq ac-show-menu-immediately-on-auto-complete t)
(setq ac-trigger-key nil)
;; fix auto completion
(ac-flyspell-workaround)
;;;;;;;;;;;;;;;
;; yasnippet ;;
;;;;;;;;;;;;;;;
(yas/initialize)
(yas/load-directory "~/.emacs.d/snippets")
;;;;;;;;;;;;;;
;; anything ;;
;;;;;;;;;;;;;;
(require 'anything)
(require 'anything-config)
(setq anything-sources
(list anything-c-source-buffers
anything-c-source-file-name-history
anything-c-source-info-pages
anything-c-source-man-pages
anything-c-source-file-cache
anything-c-source-emacs-commands))
(global-set-key (kbd "M-X") 'anything)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; centralised backup location ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar backup-dir (expand-file-name "~/.emacs.d/backup/"))
(defvar autosave-dir (expand-file-name "~/.emacs.d/autosave/"))
(setq backup-directory-alist (list (cons ".*" backup-dir)))
(setq auto-save-list-file-prefix autosave-dir)
(setq auto-save-file-name-transforms `((".*" ,autosave-dir t)))
(setq backup-by-copying t ; Don't de-link hard links
version-control t ; Use version numbers on backups
delete-old-versions t ; Automatically delete excess backups:
kept-new-versions 20 ; how many of the newest versions to keep
kept-old-versions 5) ; and how many of the old
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; automatically save and restore sessions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq desktop-path '("~/.emacs.d/desktop")
desktop-dirname "~/.emacs.d/desktop"
desktop-base-file-name "emacs-desktop"
desktop-base-lock-name "lock"
desktop-path (list desktop-dirname)
desktop-save t
desktop-files-not-to-save "^$" ;reload tramp paths
desktop-load-locked-desktop nil)
(desktop-save-mode 1)
;;;;;;;;;;;;;;;;;;;;;;;
;; language specific ;;
;;;;;;;;;;;;;;;;;;;;;;;
;; enable php mode
(autoload 'php-mode "php-mode" "Major mode for editing php code." t)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))
;; show python whitespace
(require 'python)
(add-hook 'python-mode-hook
(lambda () (interactive) (setq show-trailing-whitespace t)))
;; Colourise CSS colour literals
(autoload 'rainbow-turn-on "rainbow-mode" "Enable rainbow mode colour literal overlays")
(add-hook 'css-mode-hook 'rainbow-turn-on)
(add-hook 'html-mode-hook 'rainbow-turn-on)
(add-hook 'sass-mode-hook 'rainbow-turn-on)
;; yaml mode
(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
(add-hook 'yaml-mode-hook
'(lambda ()
(define-key yaml-mode-map "\C-m" 'newline-and-indent)))
;;;;;;;;;;;;;
;; flymake ;;
;;;;;;;;;;;;;
;; install pyflakes to check python code
(require 'flymake-cursor)
(global-set-key [f4] 'flymake-goto-next-error)
(when (load "flymake" t)
(add-to-list 'flymake-allowed-file-name-masks '("\\.php$" flymake-php-init))
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pyflakes" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init))
(defun flymake-html-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "tidy" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.html$\\|\\.ctp" flymake-html-init))
(add-to-list 'flymake-err-line-patterns
'("line \\([0-9]+\\) column \\([0-9]+\\) - \\(Warning\\|Error\\): \\(.*\\)"
nil 1 2 4))
)
;;;;;;;;;;;;;;;;;;;;
;; spell checking ;;
;;;;;;;;;;;;;;;;;;;;
(if (file-exists-p "/usr/bin/hunspell")
(progn
(setq ispell-program-name "hunspell")
(eval-after-load "ispell"
'(progn (defun ispell-get-coding-system () 'utf-8)))))
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(defun turn-on-flyspell ()
"Force flyspell-mode on using a positive arg. For use in hooks."
(interactive)
(flyspell-mode 1))
;; enable for text modes
(add-hook 'message-mode-hook 'turn-on-flyspell)
(add-hook 'text-mode-hook 'turn-on-flyspell)
(add-hook 'fundamental-mode 'turn-on-flyspell)
;; fix warning message
(setq flyspell-issue-welcome-flag nil)
;; Enable for all languages
(dolist (hook '(lisp-mode-hook
emacs-lisp-mode-hook
scheme-mode-hook
clojure-mode-hook
ruby-mode-hook
yaml-mode
python-mode-hook
shell-mode-hook
php-mode-hook
css-mode-hook
haskell-mode-hook
caml-mode-hook
nxml-mode-hook
crontab-mode-hook
perl-mode-hook
tcl-mode-hook
javascript-mode-hook))
(add-hook hook 'flyspell-prog-mode))
;;;;;;;;;;;;;;;;;
;; misc tweaks ;;
;;;;;;;;;;;;;;;;;
;; font size
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
;; syntax highlighting everywhere
(global-font-lock-mode t)
;; higlight changes in documents
;;(global-highlight-changes-mode t)
;;(set-face-foreground 'highlight-changes nil)
;;(set-face-background 'highlight-changes "#001B1C")
;;(set-face-foreground 'highlight-changes-delete nil)
;;(set-face-background 'highlight-changes-delete "#261515")
;; get rid of the blinking cursor
(blink-cursor-mode 0)
;; inhibit splash screen
(setq inhibit-splash-screen t)
;; make emacs use the clipboard
(setq x-select-enable-clipboard t)
;; setup y/n shortcut
(defalias 'yes-or-no-p 'y-or-n-p)
;; tab settings
(setq c-basic-indent 2)
(setq tab-width 4)
(setq indent-tabs-mode nil)
;; highlight parentheses
(define-globalized-minor-mode global-highlight-parentheses-mode
highlight-parentheses-mode
(lambda ()
(highlight-parentheses-mode t)))
(global-highlight-parentheses-mode t)
;; make bell visible
(setq visible-bell t)
;; always show line numbers
(global-linum-mode 1)
;; show column number
(column-number-mode 1)
;; scroll line by line
(setq scroll-step 1)
;; highlight current line
(global-hl-line-mode 1)
;;(set-face-background 'hl-line "#330")
;; enter compressed archives transparently
(auto-compression-mode 1)
;; Set this to whatever browser you use
;; (setq browse-url-browser-function 'browse-url-firefox)
;; (setq browse-url-browser-function 'browse-default-macosx-browser)
;; (setq browse-url-browser-function 'browse-default-windows-browser)
;; (setq browse-url-browser-function 'browse-default-kde)
;; (setq browse-url-browser-function 'browse-default-epiphany)
;; (setq browse-url-browser-function 'browse-default-w3m)
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "chromium-browser")
;; enable cua mode
(cua-mode t)
(setq cua-auto-tabify-rectangles nil)
(transient-mark-mode 1)
(setq cua-keep-region-after-copy t)
;; select all
(global-set-key "\C-a" 'mark-whole-buffer)
;; enable ido mode
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(setq ido-use-filename-at-point nil)
(ido-mode 1)
;; ctrl+tab buffer switch
(global-set-key [C-tab] 'next-buffer)
(global-set-key [C-S-iso-lefttab] 'previous-buffer)
;; easy window switching
(windmove-default-keybindings 'meta)
;; suppress gtk dialogues
(setq use-file-dialog nil)
(setq use-dialog-box nil)
(setq inhibit-startup-screen t)
;; Kills live buffers, leaves some emacs work buffers
;; optained from http://www.chrislott.org/geek/emacs/dotemacs.html
(defun nuke-buffers (&optional list)
"For each buffer in LIST, kill it silently if unmodified. Otherwise ask.
LIST defaults to all existing live buffers."
(interactive)
(if (null list)
(setq list (buffer-list)))
(while list
(let* ((buffer (car list))
(name (buffer-name buffer)))
(and (not (string-equal name ""))
(not (string-equal name "*Messages*"))
;; (not (string-equal name "*Buffer List*"))
(not (string-equal name "*buffer-selection*"))
(not (string-equal name "*Shell Command Output*"))
(not (string-equal name "*scratch*"))
(/= (aref name 0) ? )
(if (buffer-modified-p buffer)
(if (yes-or-no-p
(format "Buffer %s has been edited. Kill? " name))
(kill-buffer buffer))
(kill-buffer buffer))))
(setq list (cdr list))))