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.

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