This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
init.el
73 lines (69 loc) · 2.7 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
;; -*- lexical-binding: t; -*-
(defun my-memoize (f)
(let ((cache (make-hash-table :test 'equal))
(not-found (make-symbol "not-found")))
(lambda (&rest args)
(let ((hit (gethash args cache not-found)))
(if (eq hit not-found)
(let ((result (apply f args)))
(puthash args result cache)
result)
hit)))))
;; so very silly
(setq package--init-file-ensured t)
(defvar my-init-time 0)
;; see http://emacs.stackexchange.com/questions/539/how-do-i-measure-performance-of-elisp-code
(defmacro with-timer (&rest forms)
"Run the given FORMS, counting and displaying the elapsed time."
(declare (indent 0))
(let ((nowvar (make-symbol "now"))
(body `(progn ,@forms)))
`(let ((,nowvar (current-time)))
(prog1 ,body
(let ((elapsed (float-time (time-subtract (current-time) ,nowvar))))
(setq my-init-time (+ my-init-time elapsed))
(when (> elapsed 0.001)
(message "spent (%.3fs)" elapsed)))))))
;; see http://endlessparentheses.com/init-org-Without-org-mode.html
(let (errors)
(with-temp-buffer
(insert-file "~/.emacs.d/init.org")
(goto-char (point-min))
(search-forward "\n* Init")
(while (not (eobp))
(forward-line 1)
(cond
;; skip headers marked as TODO
((looking-at "^\\(\\*+\\) TODO +.*$")
(when (ignore-errors (search-forward (format "\n%s " (match-string 1))
nil t))
(forward-line -1))) ; avoid (forward-line 1) messing this up
;; report headers
((looking-at "\\*\\{2,3\\} +.*$")
(message "%s" (match-string 0)))
;; evaluate code blocks
((looking-at "^#\\+BEGIN_SRC +emacs-lisp.*$")
(let (src-beg src-end)
(condition-case error
(progn
(setq src-beg (match-end 0))
(search-forward "\n#+END_SRC")
(setq src-end (match-beginning 0))
(with-timer (eval-region src-beg src-end)))
(error
(push (format "%s for:\n%s\n\n---\n"
(error-message-string error)
(buffer-substring src-beg src-end))
errors)))))
;; finish on the next level-1 header
((looking-at "^\\* ")
(goto-char (point-max))))))
(message "pre-init: (%.3fs)" my-init-time)
(when errors
(with-current-buffer (get-buffer-create "*init errors*")
(insert (format "%i error(s) found\n\n" (length errors)))
(dolist (error (nreverse errors))
(insert error "\n"))
(goto-char (point-min))
(special-mode))
(setq initial-buffer-choice (lambda () (get-buffer "*init errors*")))))