init.el 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ;;; init.el --- Init file -*- lexical-binding: t -*-
  2. ;; Copyright © 2012–2018 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;; Hacks to reduce the startup time:
  16. ;; <https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/>
  17. (setq gc-cons-threshold (expt 2 24)) ; 16 MiB
  18. (setq load-prefer-newer t)
  19. ;;; Location of various files
  20. (defmacro al/file-accessors (name val)
  21. "Define variable and function for accessing my directories."
  22. (let ((dir-var (intern (concat "al/" name "-dir")))
  23. (file-fun (intern (concat "al/" name "-dir-file"))))
  24. `(progn
  25. (defvar ,dir-var ,val)
  26. (defun ,file-fun (file)
  27. ,(format "Return full file name of a FILE placed in `%s'."
  28. dir-var)
  29. (expand-file-name file ,dir-var)))))
  30. (al/file-accessors "emacs-init"
  31. (file-name-directory
  32. (file-truename load-file-name)))
  33. (al/file-accessors "emacs" (al/emacs-init-dir-file "../"))
  34. (al/file-accessors "emacs-data" (al/emacs-dir-file "data"))
  35. (al/file-accessors "emacs-utils" (al/emacs-dir-file "utils"))
  36. (al/file-accessors "emacs-my-packages" (al/emacs-dir-file "packages"))
  37. (al/file-accessors "gnus" (al/emacs-data-dir-file "gnus"))
  38. (al/file-accessors "gnus-news" (al/gnus-dir-file "news"))
  39. (al/file-accessors "gnus-mail" (al/gnus-dir-file "mail"))
  40. (al/file-accessors "gnus-saved" (al/gnus-dir-file "saved"))
  41. (al/file-accessors "config" "~/config")
  42. (al/file-accessors "notes" "~/notes")
  43. (al/file-accessors "progs" "~/progs")
  44. (al/file-accessors "journal" (al/notes-dir-file "journal"))
  45. (al/file-accessors "music" "~/music")
  46. (al/file-accessors "sound" "~/docs/audio/small")
  47. (al/file-accessors "tmp" "~/tmp")
  48. (al/file-accessors "src" "~/src")
  49. (al/file-accessors "devel" "~/devel")
  50. (al/file-accessors "download" "~/downloads")
  51. (al/file-accessors "echo-download" (al/download-dir-file "echo"))
  52. ;;; Guix stuff
  53. (al/file-accessors "guix-profile" "~/.guix-profiles")
  54. (al/file-accessors "guix-system-profile" "/run/current-system/profile")
  55. (defvar al/guix-system?
  56. (file-exists-p al/guix-system-profile-dir)
  57. "Non-nil, if current OS is GuixSD.")
  58. (defvar al/guix-profile-names
  59. '("emacs" "fonts" "games" "build" "guile" "misc" "main"))
  60. (defun al/guix-profile (name)
  61. "Return file name of my guix profile with NAME."
  62. (al/guix-profile-dir-file (concat name "/" name)))
  63. (defun al/guix-profiles ()
  64. "Return a list of all my guix profiles."
  65. (mapcar #'al/guix-profile al/guix-profile-names))
  66. (al/file-accessors "guix-user-profile" (al/guix-profile "main"))
  67. ;;; (Auto)loading various files
  68. (defvar al/pure-config? (getenv "EMPURE")
  69. "Non-nil, if external packages should not be loaded.")
  70. (setq
  71. package-user-dir (al/emacs-data-dir-file "elpa")
  72. package-enable-at-startup nil)
  73. (push al/emacs-utils-dir load-path)
  74. (let (file-name-handler-alist)
  75. ;; Loading my utils required for the rest config.
  76. (require 'al-autoload)
  77. (require 'al-file)
  78. (require 'al-misc)
  79. (require 'al-text)
  80. ;; Autoloading my utils.
  81. (let ((auto-file (al/autoloads-file al/emacs-utils-dir)))
  82. (unless (file-exists-p auto-file)
  83. (with-demoted-errors "ERROR during generating utils autoloads: %S"
  84. (al/update-autoloads al/emacs-utils-dir)))
  85. (al/load auto-file))
  86. ;; Autoloading external packages.
  87. (unless al/pure-config?
  88. (with-demoted-errors "ERROR during autoloading ELPA packages: %S"
  89. (when (require 'al-package nil t)
  90. (setq
  91. al/ignored-packages
  92. '( ;; Installed via Guix:
  93. pdf-tools
  94. bui
  95. dash
  96. emms
  97. geiser
  98. magit
  99. ;; Redundant dependencies of magit:
  100. magit-popup git-commit with-editor))
  101. (advice-add 'package-installed-p
  102. :around #'al/package-installed-p)
  103. (advice-add 'quelpa-package-install
  104. :around #'al/quelpa-package-install)
  105. (advice-add 'package-compute-transaction
  106. :around #'al/package-compute-transaction)
  107. (advice-add 'package-activate-1
  108. :around #'al/package-activate-1))
  109. (package-initialize))
  110. (with-demoted-errors "ERROR during autoloading Guix packages: %S"
  111. (when (require 'al-guix-autoload nil t)
  112. (apply #'al/guix-autoload-emacs-packages
  113. (al/guix-profiles))))
  114. (when (file-exists-p al/emacs-my-packages-dir)
  115. (with-demoted-errors "ERROR during autoloading my packages: %S"
  116. (dolist (dir (al/subdirs al/emacs-my-packages-dir))
  117. (let* ((elisp-dir (expand-file-name "elisp" dir))
  118. (dir (if (file-exists-p elisp-dir)
  119. elisp-dir
  120. dir)))
  121. (push dir load-path)
  122. (mapc #'al/load (al/find-autoloads dir)))))))
  123. (with-demoted-errors "ERROR during server start: %S"
  124. (require 'al-server)
  125. (al/server-named-start "server-emms" "server"))
  126. ;; Code for optional dependencies on external packages.
  127. (al/define-package-exists hydra defhydra)
  128. (al/define-package-exists mwim mwim-beginning)
  129. (defun al/init-load (file)
  130. "Load FILE from `al/emacs-init-dir'."
  131. (al/load (al/emacs-init-dir-file file)))
  132. ;; Loading the rest config files.
  133. (mapc #'al/init-load
  134. '("keys"
  135. "text"
  136. "packages"
  137. "settings"
  138. "files"
  139. "prog"
  140. "time"
  141. "file-modes"
  142. "mmedia"
  143. "net"
  144. "dict"
  145. "visual"
  146. "games"
  147. "custom")))
  148. (setq custom-file (al/emacs-init-dir-file "custom.el"))
  149. (message "Garbage collected %d times." gcs-done)
  150. ;;; init.el ends here