My attempt to optimize my emacs load time <1 second
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

446 lines
14 KiB

  1. ;; -*- lexical-binding: t; -*-
  2. ;; Configure Melpa
  3. (setq package--init-file-ensured t
  4. package-enable-at-startup nil
  5. ;; package-user-dir doom-elpa-dir
  6. ;; package-gnupghome-dir (expand-file-name "gpg" doom-elpa-dir)
  7. package-archives
  8. `(("gnu" . "https://elpa.gnu.org/packages/")
  9. ("melpa" . "https://melpa.org/packages/")
  10. ("org" . "https://orgmode.org/elpa/")))
  11. (package-initialize)
  12. ;; Configure Use-Package
  13. (eval-when-compile
  14. (add-to-list 'load-path (concat user-emacs-directory "elpa/use-package-20190716.1829"))
  15. (add-to-list 'load-path (concat user-emacs-directory "elpa/bind-key-20180513.430"))
  16. (require 'use-package)
  17. (require 'bind-key))
  18. ;; Compile function
  19. (defun compile-init ()
  20. "If the current buffer is 'init.el' tangled file is compiled."
  21. (when (equal (buffer-file-name)
  22. (expand-file-name (concat user-emacs-directory "init.el")))
  23. ;; Avoid running hooks when tangling.
  24. (let ((prog-mode-hook nil))
  25. (byte-compile-file (concat user-emacs-directory "init.el")))))
  26. ;; (add-hook 'after-save-hook 'compile-init)
  27. ;; Some Basic Init
  28. (defvar backup-dir (expand-file-name "~/.emacs.d/backup/"))
  29. (defvar autosave-dir (expand-file-name "~/.emacs.d/autosave/"))
  30. (setq initial-scratch-message nil
  31. backup-directory-alist (list (cons ".*" backup-dir))
  32. auto-save-list-file-prefix autosave-dir
  33. auto-save-file-name-transforms `((".*" ,autosave-dir t)))
  34. ;; Turn off the menus, scrollbars, and toolbars
  35. (menu-bar-mode 0)
  36. (scroll-bar-mode 0)
  37. (tool-bar-mode 0)
  38. (global-linum-mode t)
  39. (global-auto-revert-mode t)
  40. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  41. ;; Set auth source
  42. ;; (setq auth-sources '("~/.authinfo.gpg"))
  43. (defalias 'yes-or-no-p 'y-or-n-p)
  44. (defun display-startup-echo-area-message ()
  45. "Display startup echo area message."
  46. (message "Initialized in %s" (emacs-init-time)))
  47. (defun leo--find-user-init-file ()
  48. "Edit the `~/.emacs.d/init.el' file."
  49. (interactive)
  50. (find-file "~/.emacs.d/init.el"))
  51. (defun leo--tidy ()
  52. "Indent, untabify and unwhitespacify current buffer, or region if active."
  53. (interactive)
  54. (let ((beg (if (region-active-p) (region-beginning) (point-min)))
  55. (end (if (region-active-p) (region-end) (point-max))))
  56. (let ((inhibit-message t))
  57. (indent-region beg end))
  58. (whitespace-cleanup)
  59. (untabify beg (if (< end (point-max)) end (point-max)))
  60. (if (region-active-p) (message "Indenting Region...Done") (message "Indenting File...Done"))))
  61. (defun leo--comment-or-uncomment-region-or-line ()
  62. "Comment or uncomment the region or the current line if there's no active region."
  63. (interactive)
  64. (let (beg end)
  65. (if (region-active-p)
  66. (setq beg (region-beginning) end (region-end))
  67. (setq beg (line-beginning-position) end (line-end-position)))
  68. (comment-or-uncomment-region beg end)))
  69. (defun leo--duplicate-thing (comment)
  70. "Duplicates the current line, or the region if active. If an argument (COMMENT) is given, the duplicated region will be commented out."
  71. (interactive "P")
  72. (save-excursion
  73. (let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
  74. (end (if (region-active-p) (region-end) (point-at-eol))))
  75. (goto-char end)
  76. (unless (region-active-p)
  77. (newline))
  78. (insert (buffer-substring start end))
  79. (when comment (comment-region start end)))))
  80. (defun leo--kill-this-buffer-unless-scratch ()
  81. "Works like `kill-this-buffer' unless the current buffer is the *scratch* buffer. In which case the buffer content is deleted and the buffer is buried."
  82. (interactive)
  83. (if (or (string= (buffer-name) "*dashboard*") (string= (buffer-name) "*scratch*"))
  84. (progn
  85. (bury-buffer (buffer-name))
  86. (switch-to-buffer (other-buffer)))
  87. (kill-this-buffer)))
  88. (defun leo--jump-to-symbol (&optional backwardp)
  89. "Jumps to the next symbol near the point if such a symbol exists. If BACKWARDP is non-nil it jumps backward."
  90. (let* ((point (point))
  91. (bounds (find-tag-default-bounds))
  92. (beg (car bounds)) (end (cdr bounds))
  93. (str (isearch-symbol-regexp (find-tag-default)))
  94. (search (if backwardp 'search-backward-regexp
  95. 'search-forward-regexp)))
  96. (goto-char (if backwardp beg end))
  97. (funcall search str nil t)
  98. (cond ((<= beg (point) end) (goto-char point))
  99. (backwardp (forward-char (- point beg)))
  100. (t (backward-char (- end point))))))
  101. (defun leo--jump-to-prev-symbol ()
  102. "Jumps to the previous occurrence of the symbol at point."
  103. (interactive)
  104. (leo--jump-to-symbol t))
  105. (defun leo--jump-to-next-symbol ()
  106. "Jumps to the next occurrence of the symbol at point."
  107. (interactive)
  108. (leo--jump-to-symbol))
  109. ;; USE PACKAGE help
  110. ;; (use-package package-here
  111. ;; :commands (cmd cmd-all cmd-etc) ;; List commands used to ":defer" the package
  112. ;; :bind-keymap
  113. ;; ("M-q" . package-here-keymap) ;; Setup an entire keymap using Prefix "M-q"
  114. ;; :bind
  115. ;; (("M-s" . cmd) ;; Available Globally
  116. ;; :map here-mode-map
  117. ;; ("C-t" . cmd-all) ;; Available only in "here-mode"
  118. ;; ("C-e" . cmd-etc)) ;; Available only in "here-mode"
  119. ;; :init
  120. ;; (setq stuff t) ;; declar vars etc...
  121. ;; :config
  122. ;; (here-mode 1) ;; eval stuff here after the init
  123. ;;
  124. ;; (use-package ruby-mode
  125. ;; :mode "\\.rb\\'"
  126. ;; :interpreter "ruby"
  127. ;;
  128. ;; ;; OR when the package name isn't the same as the =mode=
  129. ;; (use-package python
  130. ;; :mode ("\\.py\\'" . python-mode)
  131. ;; :interpreter ("python" . python-mode))
  132. ;;
  133. ;; USE ":defer" when you aren't using either :commands, :bind, :bind*, :bind-keymap, :bind-keymap*, :mode, :interpreter, or :hook
  134. ;; (use-package deferred-package
  135. ;; :defer t)
  136. (use-package bind-key
  137. :ensure t
  138. :bind
  139. ("C-<tab>" . leo--tidy)
  140. ("C-;" . leo--comment-or-uncomment-region-or-line)
  141. ("C-c e" . leo--find-user-init-file)
  142. ("M-q" . leo--kill-this-buffer-unless-scratch)
  143. ("C-c d" . leo--duplicate-thing)
  144. ("M-n" . leo--jump-to-next-symbol)
  145. ("M-p" . leo--jump-to-prev-symbol)
  146. ("M-u" . upcase-dwim)
  147. ("M-c" . capitalize-dwim)
  148. ("M-l" . downcase-dwim)
  149. )
  150. (use-package better-defaults
  151. :ensure t)
  152. (use-package base16-theme
  153. :ensure t
  154. :config
  155. (load-theme 'base16-onedark t))
  156. ;; https://github.com/Fanael/rainbow-delimiters
  157. (use-package rainbow-delimiters
  158. :ensure t
  159. :hook (prog-mode . rainbow-delimiters-mode))
  160. ;; M-x all-the-icons-install-fonts
  161. (use-package all-the-icons
  162. :ensure t)
  163. (use-package doom-modeline
  164. :ensure t
  165. :after (all-the-icons)
  166. :hook (after-init . doom-modeline-mode))
  167. (use-package dashboard
  168. :ensure t
  169. :init
  170. (setq dashboard-items '((recents . 6)
  171. (bookmarks . 5)
  172. ;; (projects . 5)
  173. (agenda . 5)))
  174. (setq dashboard-center-content t)
  175. (setq dashboard-banner-logo-title "Let's begin...")
  176. (setq dashboard-startup-banner 1)
  177. (setq dashboard-show-shortcuts t)
  178. (setq show-week-agenda-p t)
  179. (setq dashboard-org-agenda-categories '("work" "tasks"))
  180. :config
  181. (dashboard-setup-startup-hook))
  182. (use-package helm
  183. :ensure t
  184. :demand t
  185. :bind
  186. ("M-x" . helm-M-x)
  187. ("C-c b" . helm-buffers-list)
  188. ("C-x C-f" . helm-find-files))
  189. ;; https://github.com/emacsorphanage/helm-swoop
  190. (use-package helm-swoop
  191. :ensure t
  192. :after (helm)
  193. :bind
  194. ("C-s" . helm-swoop)
  195. :config
  196. ;; If you prefer fuzzy matching
  197. (setq helm-swoop-use-fuzzy-match t))
  198. ;; https://github.com/syohex/emacs-helm-ag
  199. (use-package helm-ag
  200. :ensure t
  201. :after (helm)
  202. :bind
  203. ("C-c k" . helm-ag))
  204. (use-package expand-region
  205. :ensure t
  206. :bind
  207. ("C-@" . er/expand-region)
  208. ("C-#" . er/contract-region))
  209. ;; https://github.com/magnars/multiple-cursors.el
  210. (use-package multiple-cursors
  211. :ensure t
  212. :bind
  213. ("C-}" . mc/mark-next-like-this)
  214. ("C-)" . mc/unmark-next-like-this)
  215. ("C-{" . mc/mark-previous-like-this)
  216. ("C-(" . mc/unmark-previous-like-this))
  217. ;; https://github.com/justbur/emacs-which-key
  218. (use-package which-key
  219. :ensure t
  220. :config
  221. (which-key-setup-minibuffer)
  222. (which-key-mode))
  223. ;; https://github.com/lewang/fic-mode
  224. (use-package fic-mode
  225. :ensure t
  226. :hook prog-mode)
  227. ;; https://github.com/joaotavora/yasnippet
  228. (use-package yasnippet
  229. :ensure t
  230. :bind ("<tab>" . yas-expand)
  231. :init
  232. (setq yas-snippet-dirs (list (concat user-emacs-directory "snippets")))
  233. :config
  234. (yas-reload-all)
  235. (yas-minor-mode 1))
  236. ;; https://company-mode.github.io/
  237. (use-package company
  238. :ensure t
  239. :hook (prog-mode . company-mode))
  240. ;; https://github.com/magit/magit
  241. (use-package magit
  242. :commands magit-status
  243. :ensure t
  244. :init
  245. (setq magit-completing-read-function 'helm-completing-read-default-handler)
  246. :bind
  247. ("C-x g" . magit-status)
  248. ("C-c g" . magit-status))
  249. ;; https://github.com/bbatsov/projectile
  250. (use-package projectile
  251. :ensure t
  252. :bind-keymap
  253. ("C-c p" . projectile-command-map)
  254. )
  255. ;; https://github.com/magit/git-modes
  256. (use-package gitignore-mode
  257. :ensure t)
  258. ;; https://github.com/magit/git-modes
  259. (use-package gitconfig-mode
  260. :ensure t)
  261. ;; http://web-mode.org/
  262. (use-package web-mode
  263. :ensure t
  264. :mode "\\.html?\\'")
  265. ;; https://github.com/joshwnj/json-mode
  266. (use-package json-mode
  267. :ensure t
  268. :mode "\\.json\\'")
  269. ;; https://orgmode.org/elpa.html
  270. (use-package org
  271. :commands (org-cycle-agenda-files org-capture)
  272. :ensure org-plus-contrib
  273. :mode ("\\.org\\'" . org-mode)
  274. :bind (
  275. ("C-," . org-cycle-agenda-files)
  276. ("C-c C-d" . org-capture)
  277. :map org-mode-map
  278. ("M-RET" . org-insert-todo-heading)
  279. )
  280. :init
  281. (setq org-agenda-files '("~/Dropbox/Org/todo.org"
  282. "~/Dropbox/Org/archive.org"
  283. "~/Dropbox/Org/diary/eaglecrk.org"))
  284. (setq org-todo-keywords '((sequence "TODO(t)" "|" "DONE(d)")
  285. (sequence "BUG(b)" "INPROGRESS(i)" "|" "FIXED(f)")
  286. (sequence "TEST(T)" "NOTEST(N)" "|" "COMPLETE(C)")
  287. (sequence "|" "CANCELED(c)")
  288. (sequence "|" "NEEDCLARIFICATION(n)")
  289. (sequence "|" "PROVIDEUPDATE(p)")
  290. (sequence "|" "WAITING(w)"))
  291. org-refile-targets '((nil :maxlevel . 3)
  292. (org-agenda-files :maxlevel . 3))
  293. org-directory "~/Dropbox/Org"
  294. org-default-notes-file (concat org-directory "/todo.org")
  295. org-startup-folded t
  296. org-startup-indented t
  297. org-startup-align-all-tables t
  298. org-startup-with-inline-images t
  299. org-startup-with-latex-preview t
  300. org-src-tab-acts-natively t
  301. org-confirm-babel-evaluate nil
  302. org-log-done t
  303. org-log-done-with-time t
  304. org-log-into-drawer t
  305. org-hide-leading-stars t
  306. org-pretty-entities t
  307. org-use-property-inheritance t
  308. org-html-validation-link nil
  309. org-html-text-markup-alist '((bold . "<b>%s</b>")
  310. (code . "<code>%s</code>")
  311. (italic . "<i>%s</i>")
  312. (strike-through . "<del>%s</del>")
  313. (underline . "<span class=\"underline\">%s</span>")
  314. (verbatim . "<code class=\"verbatim\">%s</code>"))
  315. )
  316. :config
  317. (org-babel-do-load-languages 'org-babel-load-languages '((js . t)
  318. (shell . t)
  319. (emacs-lisp . t)))
  320. (add-to-list 'org-structure-template-alist
  321. (list "e" (concat "#+BEGIN_SRC emacs-lisp :results silent\n"
  322. "\n"
  323. "#+END_SRC")))
  324. (add-to-list 'org-structure-template-alist
  325. (list "j" (concat "#+BEGIN_SRC js :cmd \"/usr/local/bin/babel-node\" :results output code\n"
  326. "\n"
  327. "#+END_SRC")))
  328. (add-to-list 'org-structure-template-alist
  329. (list "r" (concat "#+BEGIN_SRC restclient :results raw\n"
  330. "\n"
  331. "#+END_SRC")))
  332. )
  333. ;; https://github.com/sabof/org-bullets
  334. (use-package org-bullets
  335. :ensure t
  336. :after (org)
  337. :hook (org-mode . org-bullets-mode)
  338. :config
  339. (set-face-attribute 'org-level-1 nil :height 1.3)
  340. (set-face-attribute 'org-level-2 nil :height 1.1)
  341. (set-face-attribute 'org-level-3 nil :height 1.05)
  342. (set-face-attribute 'org-level-4 nil :height 1.05)
  343. (set-face-attribute 'org-scheduled-today nil :height 1.0)
  344. (set-face-attribute 'org-agenda-date-today nil :height 1.1))
  345. ;; https://orgmode.org/worg/org-contrib/org-protocol.html
  346. (use-package org-protocol
  347. :ensure org-plus-contrib
  348. :after (org)
  349. :init
  350. (setq org-capture-templates
  351. '(("t" "new task" entry (file+headline "~/Dropbox/Org/todo.org" "Tasks")
  352. "* TODO [#A] %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n")
  353. ("n" "new note" entry (file+headline org-default-notes-file "Notes")
  354. "* %?\n%i\n")
  355. ("l" "store link" entry (file+olp org-default-notes-file "Links" "Unfiled")
  356. "* %a\n%?\n")
  357. ("d" "store link w/drawer" entry (file+olp org-default-notes-file "Links" "Unfiled")
  358. "* %?\n%l\n:COPIED_TEXT:\n %i\n:END:\n")
  359. ("f" "dotfile" entry (file+headline "~/Dropbox/Org/dotfiles.org" "Other")
  360. "* %?\n:PROPERTIES:\n:CUSTOM_ID: %(org-id-get-create)\n:END:\n")
  361. ))
  362. )
  363. (cond ((member "PragmataPro Liga" (font-family-list))
  364. (set-face-attribute 'default nil :font "PragmataPro Liga-12")))
  365. (server-start)
  366. ;; Reset GC as late as possible
  367. ;; (add-hook 'emacs-startup-hook
  368. ;; (setq gc-cons-threshold 16777216
  369. ;; gc-cons-percentage 0.1))
  370. (custom-set-variables
  371. ;; custom-set-variables was added by Custom.
  372. ;; If you edit it by hand, you could mess it up, so be careful.
  373. ;; Your init file should contain only one such instance.
  374. ;; If there is more than one, they won't work right.
  375. '(package-selected-packages
  376. (quote
  377. (org-bullets org-plus-contrib web-mode gitconfig-mode gitignore-mode rainbow-delimiters company company-mode projectile magit helm-ag helm-swoop yasnippet fic-mode which-key pdf-tools better-defaults use-package)))
  378. '(safe-local-variable-values (quote ((whitespace-line-column . 120)))))
  379. (custom-set-faces
  380. ;; custom-set-faces was added by Custom.
  381. ;; If you edit it by hand, you could mess it up, so be careful.
  382. ;; Your init file should contain only one such instance.
  383. ;; If there is more than one, they won't work right.
  384. )