forked from ran9er/init.emacs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsite-start.el
127 lines (114 loc) · 4.23 KB
/
site-start.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
(unless (boundp '*init-dir*)
(let* (init-time
(init-name-match "init.*emacs\\|emacs.*init")
(base-dir
(apply 'expand-file-name
(if (eq system-type 'windows-nt)
(list ".." exec-directory)
(list "~" nil))))
(init-dir
(file-name-as-directory
(or
(car
(sort
(mapcar (lambda (x) (if (file-directory-p x) x (make-temp-name "")))
(directory-files base-dir t init-name-match t))
'file-newer-than-file-p))
(make-temp-name ""))))
(init-files
(mapcar
(lambda (f) (file-name-sans-extension f))
(directory-files init-dir t "\\.el\\'"))))
(when (file-exists-p init-dir)
(setq init-time (list (float-time)))
;; export *init-dir*
(defvar *init-dir* init-dir)
;; add "_xxx_" to load-path
(mapc (lambda (p)
(if (file-directory-p p)
(add-to-list 'load-path p)))
(directory-files init-dir t "^_.*_\\'"))
;; autoload
(funcall
(lambda (dir &optional loaddefs basedir)
(let* ((path
(expand-file-name dir (or basedir *init-dir*)))
(ldfs
(or loaddefs "_loaddefs"))
(generated-autoload-file
(expand-file-name ldfs path)))
(update-directory-autoloads path)
(kill-buffer ldfs)
(load generated-autoload-file)))
"_autoload_/")
;; *auto-hook-hash*
(defvar *auto-hook-hash* (make-hash-table :test 'equal :size 20))
(mapc
(lambda (x)
(puthash
(file-name-sans-extension (file-name-nondirectory x)) x
*auto-hook-hash*))
(directory-files (expand-file-name "_extensions/" init-dir) t "\\.el\\'"))
(add-hook 'find-file-hook
'(lambda ()
(let* ((bf (buffer-name))
(mode
(catch 'md
(mapcar
(lambda (x)
(and
(string-match (car x) bf)
(throw 'md (symbol-name (cdr x)))))
auto-mode-alist))))
;; (setq mode
;; (or mode
;; (and (string-equal "*" (substring bf 0 1))
;; (substring bf 1 -1))))
(load
(gethash mode *auto-hook-hash*
(make-temp-name ""))
t))))
;; byte-compile
(when nil
;; delete elc without el
(mapc (lambda(f)(or (file-exists-p (substring f 0 -1))
(delete-file f)))
(directory-files init-dir t "\\.elc\\'"))
;; recompile
(eval-when-compile (require 'bytecomp))
(mapc (lambda(f) (byte-recompile-file f nil 0))
(directory-files init-dir t "\\.el\\'")))
;; load *.elc || *.el in init-dir
(defvar *init-time* nil)
(let (tm)
(mapc
(lambda (f)
(setq tm (float-time))
(load f)
(setq *init-time*
(cons
(cons
(file-name-nondirectory f)
(- (float-time) tm))
*init-time*)))
init-files))
(setcdr init-time (float-time))
(let ((total (- (cdr init-time) (car init-time))))
(setq *init-time*
(append
(list
(cons 'Total
total)
(cons 'other
(- total
(apply '+ (mapcar 'cdr *init-time*))))
'---------------------------------------------)
*init-time*)))
;; when init finished, echo some info
(add-hook
'emacs-startup-hook
`(lambda ()
(message "load %d init file , spend %g seconds ; startup spend %g seconds"
(- (length *init-time*) 3)
(cdar *init-time*)
(- (float-time) ,(car init-time))))))))