forked from emacs-exordium/exordium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
421 lines (340 loc) · 16.2 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
;;;; ___ __ __ __
;;;; |__ \_/ / \ |__) | \ | | | |\/|
;;;; |___ / \ \__/ | \ |__/ | \__/ | |
;;;;
;;;; Emacs Makes All Computing Simple.
;; Reduce the frequency of garbage collection by making it happen on
;; each 100MB of allocated data (the default is on every 0.76MB). This reduces
;; the startup time.
(setq gc-cons-threshold 100000000)
(let ((min-version "24.4"))
(when (version< emacs-version min-version)
(error "This config requires at least Emacs %s, but you're running %s"
min-version emacs-version)))
(setq initial-scratch-message
"EXORDIUM DID NOT LOAD CORRECTLY.
Check the warnings and messages buffers, or restart with --debug-init")
(defconst exordium-before-init "before-init.el"
"name of the before init file")
(defconst exordium-prefs "prefs.el"
"name of the prefs file")
(defconst exordium-after-init "after-init.el"
"name of the after init file")
;; Save any custom set variable in after-init.el rather than at the end of init.el:
(setq custom-file "~/.emacs.d/after-init.el")
;; Use this file for HTTP proxy settings if needed for packages. Also add
;; additional packages to exordium-extra-packages for packages to be
;; automatically pulled from the elpa archives
(defconst exordium-before-init-file (locate-user-emacs-file exordium-before-init)
"location of the master before init file")
(defconst exordium-modules-dir (locate-user-emacs-file "modules")
"location of the modules directory")
(defconst exordium-themes-dir (locate-user-emacs-file "themes")
"location of the themes directory")
(defconst exordium-extensions-dir (locate-user-emacs-file "extensions")
"location of the extensions directory")
(defconst exordium-local-dir (locate-user-emacs-file "local")
"location of the local directory")
(defconst exordium-prefs-file (locate-user-emacs-file exordium-prefs)
"location of the master prefs file")
(defconst exordium-after-init-file (locate-user-emacs-file exordium-after-init)
"location of the master after init file")
(defcustom exordium-extra-packages ()
"Additional packages to auto load from elpa repositories"
:group 'exordium
:type 'list)
(defcustom exordium-extra-pinned ()
"Additional packages locations to pin to"
:group 'exordium
:type 'list)
;; Taps definition of before and after files. These are loaded
;; after master 'before', 'after', and 'prefs' files
(defconst exordium-taps-root (locate-user-emacs-file "taps")
"location of the tapped directories")
(defconst exordium-tapped-before-init-files ()
"all tapped before init files, including master")
(defconst exordium-tapped-prefs-files ()
"all tapped prefs files, including master")
(defconst exordium-tapped-after-init-files ()
"all tapped after init files, including master")
(defconst exordium-melpa-package-repo "http://melpa.org/packages/"
"URL for packages repository")
(defconst exordium-pinned-melpa-package-repo "http://melpa.org/packages/"
"URL for pinned default packages. Set to stable melpa.org if you want stable")
(defconst exordium-gnu-package-repo "http://elpa.gnu.org/packages/"
"URL for the GNU package repository")
(when (file-accessible-directory-p exordium-taps-root)
(dolist (tap (nreverse (directory-files exordium-taps-root t "^[^\.][^\.]?*+")))
(when (file-accessible-directory-p tap)
(let ((tapped (concat (file-name-as-directory tap) exordium-before-init)))
(when (file-readable-p tapped)
(add-to-list 'exordium-tapped-before-init-files tapped))
(setq tapped (concat (file-name-as-directory tap) exordium-prefs))
(when (file-readable-p tapped)
(add-to-list 'exordium-tapped-prefs-files tapped))
(setq tapped (concat (file-name-as-directory tap) exordium-after-init))
(when (file-readable-p tapped)
(add-to-list 'exordium-tapped-after-init-files tapped))))))
(when (file-readable-p exordium-before-init-file)
(add-to-list 'exordium-tapped-before-init-files exordium-before-init-file))
(when (file-readable-p exordium-prefs-file)
(add-to-list 'exordium-tapped-prefs-files exordium-prefs-file))
(when (file-readable-p exordium-after-init-file)
(add-to-list 'exordium-tapped-after-init-files exordium-after-init-file))
;; Load before init files
(dolist (tapped-file exordium-tapped-before-init-files)
(load tapped-file))
;;; Packages from Melpa
;; Use M-x `package-refresh-contents' to update the cache.
;; Use M-x `package-list-package' to load and display the list of packages,
;; then press I to mark for installation and X to execute (it's like dired).
;; Initialize the package system
(require 'package)
(add-to-list 'package-archives
(cons "melpa" exordium-melpa-package-repo) t)
(add-to-list 'package-archives
(cons "melpa-pinned" exordium-pinned-melpa-package-repo) t)
(add-to-list 'package-archives
(cons "gnu" exordium-gnu-package-repo) t)
(package-initialize)
;; Load the packages we need if they are not installed already
(let ((package-pinned-packages (append '(
(diminish . "melpa-pinned")
(highlight-symbol . "melpa-pinned")
(magit . "melpa-pinned")
(git-timemachine . "melpa-pinned")
(git-gutter . "melpa-pinned")
(git-gutter-fringe . "melpa-pinned")
(expand-region . "melpa-pinned")
(auto-complete . "melpa-pinned")
(company . "melpa-pinned")
(rtags . "melpa-pinned")
(ac-rtags . "melpa-pinned")
(company-rtags . "melpa-pinned")
(helm-rtags . "melpa-pinned")
(auto-complete-c-headers . "melpa")
(yasnippet . "melpa-pinned")
(js2-mode . "melpa-pinned")
(ac-js2 . "melpa")
(iedit . "melpa")
(cider . "melpa-pinned")
(clojure-mode . "melpa-pinned")
(paredit . "melpa-pinned")
(rainbow-delimiters . "melpa-pinned")
(helm . "melpa-pinned")
(helm-descbinds . "melpa-pinned")
(helm-swoop . "melpa-pinned")
(helm-ag . "melpa-pinned")
(ido-ubiquitous . "melpa-pinned")
(projectile . "melpa-pinned")
(helm-projectile . "melpa-pinned")
(cmake-mode . "melpa-pinned")
(markdown-mode . "melpa-pinned")
(impatient-mode . "melpa-pinned")
(enh-ruby-mode . "melpa")
(fill-column-indicator . "melpa-pinned")
(exec-path-from-shell . "melpa-pinned")
(goto-chg . "melpa")
(project-explorer . "melpa-pinned")
(page-break-lines . "melpa-pinned")
(org-bullets . "melpa-pinned")
(ox-gfm . "melpa-pinned")
(powerline . "melpa-pinned")
(nlinum . "gnu")
(vlf . "melpa-pinned")
(avy . "melpa-pinned")
(ace-window . "melpa-pinned")
(highlight . "melpa-pinned")
(eval-sexp-fu . "melpa-pinned")
(modern-cpp-font-lock . "melpa-pinned")
(default-text-scale . "melpa-pinned")
(evil . "melpa-pinned")
(all-the-icons . "melpa-pinned")
(groovy-mode . "melpa-pinned")
(helm-smex . "melpa-pinned")
(helm-gtags . "melpa-pinned")
)
exordium-extra-pinned))
(has-refreshed nil))
(defun update-package (p has-refreshed)
(unless (package-installed-p p)
(unless has-refreshed
(message "Refreshing package database...")
(package-refresh-contents)
(setq has-refreshed t)
(message "Done."))
(package-install p)))
(dolist (pkg package-pinned-packages)
(let ((p (car pkg)))
(update-package p has-refreshed)))
(dolist (pkg exordium-extra-packages)
(update-package pkg has-refreshed)))
;;; Path for "require"
(add-to-list 'load-path exordium-modules-dir)
(defun add-directory-tree-to-load-path (dir &optional ignore-if-absent)
"Add DIR and all its subdirs to the load path."
(cond ((file-directory-p dir)
(add-to-list 'load-path dir)
(let ((default-directory dir))
(normal-top-level-add-subdirs-to-load-path)))
((not ignore-if-absent)
(warn "Missing directory: %s" dir))))
(add-directory-tree-to-load-path exordium-extensions-dir)
(add-directory-tree-to-load-path exordium-themes-dir)
(add-directory-tree-to-load-path exordium-local-dir t)
(setq custom-theme-directory exordium-themes-dir)
;;; Load Modules
(require 'bytecomp)
(defun recompile-modules ()
"Recompile modules for which the .elc is older than the .el, if
the .elc exists. Also discard .elc without corresponding .el"
(interactive)
(dolist (dir (list exordium-modules-dir
exordium-themes-dir
exordium-extensions-dir
exordium-local-dir))
(when (file-directory-p dir)
;; Recompile
(dolist (el (directory-files dir t "\\.el$"))
(let ((elc (byte-compile-dest-file el)))
(when (and (file-exists-p elc)
(file-newer-than-file-p el elc))
(byte-compile-file el))))
;; Discard .elc singletons
(dolist (elc (directory-files dir t "\\.elc$"))
(let ((el (concat (concat (file-name-sans-extension elc) ".el"))))
(unless (file-exists-p el)
(warn "Removing singleton .elc file: %s" elc)
(delete-file elc)))))))
(recompile-modules)
(require 'init-lib) ; utility functions - load this first
(require 'init-environment) ; environment variables
;;; Local preferences (fonts, frame size etc.)
(require 'init-prefs) ; defines variables that prefs.el can override
(dolist (tapped-file exordium-tapped-prefs-files)
(load tapped-file))
;;; Themes
;;; Note: use "export TERM=xterm-256color" for emacs -nw
(require 'init-progress-bar)
(when exordium-nw
(set-face-background 'highlight nil))
(when exordium-theme
(require 'init-themes))
;;; Desktop
(when exordium-desktop
(require 'init-desktop))
;;; Look and feel
(require 'init-look-and-feel) ; fonts, UI, keybindings, saving files etc.
(require 'init-font-lock) ; enables/disables font-lock globally.
(require 'init-linum) ; line numbers
(when exordium-smooth-scroll ; smooth scroll
(require 'init-smooth-scroll)
(smooth-scroll-mode 1))
(update-progress-bar)
;;; Usability
(require 'init-window-manager) ; navigate between windows
(require 'init-util) ; utilities like match paren, bookmarks...
(require 'init-ido) ; supercharged completion engine
(require 'init-highlight) ; highlighting current line, symbol under point
(cond ((eq exordium-complete-mode :auto-complete)
(require 'init-autocomplete)) ; auto-completion (see below for RTags AC)
((eq exordium-complete-mode :company)
(require 'init-company))) ; company mode (rtags are on by default)
(when exordium-helm-projectile ; find files anywhere in project
(require 'init-helm-projectile))
(require 'init-helm) ; setup helm
(update-progress-bar)
(require 'init-dired) ; enable dired+ and wdired permission editing
(require 'init-git) ; Magit and git gutter
(require 'init-git-visit-diffs) ; visit diffs in successive narrowed buffers
(require 'init-flb-mode) ; frame-local buffers
(update-progress-bar)
;;; Prog mode
(require 'init-prog-mode)
;;; Shell mode
(require 'init-shell)
;;; Major modes
(require 'init-markdown)
(require 'init-org)
(require 'init-xml)
;;; OS-specific things
(when exordium-osx
(require 'init-osx))
;;; C++
(require 'init-cpp)
(require 'init-bde-style)
(when exordium-yasnippet
(require 'init-yasnippet))
(require 'init-gdb)
;;; RTags
(require 'init-rtags)
(when exordium-rtags-auto-complete
(rtags-auto-complete))
(require 'init-rtags-helm)
(require 'init-rtags-cmake)
(require 'init-rtags-cdb)
(update-progress-bar)
;;; JS
(require 'init-javascript)
;;; Python
(require 'init-python)
;;; Ruby
(require 'init-ruby)
;;; Lisp
(require 'init-elisp)
;;; Clojure
(when exordium-clojure
(require 'init-clojure))
(update-progress-bar)
;;; Local extensions
(dolist (tapped-file exordium-tapped-after-init-files)
(load tapped-file))
(when (and exordium-theme exordium-enable-powerline)
(require 'init-powerline))
(update-progress-bar)
(require 'helm-smex)
(global-set-key [remap execute-extended-command] #'helm-smex)
(global-set-key (kbd "M-X") #'helm-smex-major-mode-commands)
;; Enable helm-gtags-mode
(require 'init-helm-gtags)
(require 'init-keymap)
;;(defun trunk-locate ()
;; "locate files in trunk directory"
;; (interactive)
;; (setq current-prefix-arg '("/home/binbzhu/locatedb/trunk.db"))
;; (call-interactively 'helm-locate))
(setq find-grep-options "-q -i")
(defun jpk/locate-make-command-line (str)
(list locate-command "-d" "/home/binbzhu/locatedb/trunk.db" str))
(setq locate-make-command-line 'jpk/locate-make-command-line)
;;using esc to end entering
;;(global-set-key (kbd "<escape>") 'keyboard-quit)
(setq-default c-basic-offset 4)
(global-set-key (kbd "C-c l") 'helm-locate)
;;(defun insert_cplane_header
;; ())
(defun copy-path-file-name-to-clipboard ()
"Copy the current buffer file name to the clipboard."
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(when filename
(kill-new filename)
(message "Copied buffer file name '%s' to the clipboard." filename))))
(defun copy-file-name-to-clipboard ()
"Copy the current buffer file name to the clipboard."
(interactive)
(let ((filename (file-name-nondirectory
(if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name)))))
(when filename
(kill-new filename)
(message "Copied buffer file name '%s' to the clipboard." filename))))
;;; Greetings
(setq initial-scratch-message
(let ((current-user (split-string (user-full-name) " ")))
(format ";; Happy hacking %s!
" (if current-user (car current-user) exordium-current-user))))
;;; End of file