2017-06-08 11:47:56 +02:00
|
|
|
;;; core.el --- the heart of the beast -*- lexical-binding: t; -*-
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2019-11-07 12:49:30 -05:00
|
|
|
(when (version< emacs-version "26.1")
|
|
|
|
(error "Detected Emacs %s. Doom only supports Emacs 26.1 and higher"
|
2019-10-17 01:47:58 -04:00
|
|
|
emacs-version))
|
|
|
|
|
2019-09-03 00:42:36 -04:00
|
|
|
(defconst doom-version "2.0.9"
|
|
|
|
"Current version of Doom Emacs.")
|
|
|
|
|
2019-11-17 16:47:56 -05:00
|
|
|
(defconst EMACS27+ (> emacs-major-version 26))
|
2020-04-27 02:12:47 -04:00
|
|
|
(defconst EMACS28+ (> emacs-major-version 27))
|
2019-09-03 00:42:36 -04:00
|
|
|
(defconst IS-MAC (eq system-type 'darwin))
|
|
|
|
(defconst IS-LINUX (eq system-type 'gnu/linux))
|
|
|
|
(defconst IS-WINDOWS (memq system-type '(cygwin windows-nt ms-dos)))
|
|
|
|
(defconst IS-BSD (or IS-MAC (eq system-type 'berkeley-unix)))
|
|
|
|
|
2020-05-03 09:45:53 +02:00
|
|
|
;; Unix tools looks for HOME, but this is normally not defined on Windows.
|
|
|
|
(when (and IS-WINDOWS (null (getenv "HOME")))
|
|
|
|
(setenv "HOME" (getenv "USERPROFILE")))
|
|
|
|
|
2019-10-30 00:02:04 -04:00
|
|
|
;; Ensure `doom-core-dir' is in `load-path'
|
|
|
|
(add-to-list 'load-path (file-name-directory load-file-name))
|
|
|
|
|
|
|
|
(defvar doom--initial-load-path load-path)
|
|
|
|
(defvar doom--initial-process-environment process-environment)
|
|
|
|
(defvar doom--initial-exec-path exec-path)
|
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; `file-name-handler-alist' is consulted on every `require', `load' and various
|
|
|
|
;; path/io functions. You get a minor speed up by nooping this. However, this
|
|
|
|
;; may cause problems on builds of Emacs where its site lisp files aren't
|
|
|
|
;; byte-compiled and we're forced to load the *.el.gz files (e.g. on Alpine)
|
2020-02-21 17:03:47 -05:00
|
|
|
(unless noninteractive
|
2020-03-27 02:33:25 -04:00
|
|
|
(defvar doom--initial-file-name-handler-alist file-name-handler-alist)
|
2019-10-30 00:02:04 -04:00
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
(setq file-name-handler-alist nil)
|
|
|
|
;; Restore `file-name-handler-alist', because it is needed for handling
|
|
|
|
;; encrypted or compressed files, among other things.
|
|
|
|
(defun doom-reset-file-handler-alist-h ()
|
2020-04-16 18:16:49 -04:00
|
|
|
;; Re-add rather than `setq', because file-name-handler-alist may have
|
|
|
|
;; changed since startup, and we want to preserve those.
|
|
|
|
(dolist (handler file-name-handler-alist)
|
|
|
|
(add-to-list 'doom--initial-file-name-handler-alist handler))
|
2020-03-27 02:33:25 -04:00
|
|
|
(setq file-name-handler-alist doom--initial-file-name-handler-alist))
|
|
|
|
(add-hook 'emacs-startup-hook #'doom-reset-file-handler-alist-h))
|
2019-11-21 14:43:36 -05:00
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; Just the bare necessities
|
2020-04-29 20:20:24 -04:00
|
|
|
(require 'subr-x)
|
|
|
|
(require 'cl-lib)
|
2019-10-30 00:02:04 -04:00
|
|
|
(require 'core-lib)
|
|
|
|
|
|
|
|
|
2019-09-03 00:42:36 -04:00
|
|
|
;;
|
2019-10-30 00:02:04 -04:00
|
|
|
;;; Global variables
|
|
|
|
|
2019-07-21 03:01:15 +02:00
|
|
|
(defvar doom-init-p nil
|
|
|
|
"Non-nil if Doom has been initialized.")
|
|
|
|
|
|
|
|
(defvar doom-init-time nil
|
|
|
|
"The time it took, in seconds, for Doom Emacs to initialize.")
|
2018-05-19 18:01:49 +02:00
|
|
|
|
2018-06-15 00:25:20 +02:00
|
|
|
(defvar doom-debug-mode (or (getenv "DEBUG") init-file-debug)
|
2019-05-01 19:12:52 -04:00
|
|
|
"If non-nil, Doom will log more.
|
|
|
|
|
|
|
|
Use `doom/toggle-debug-mode' to toggle it. The --debug-init flag and setting the
|
|
|
|
DEBUG envvar will enable this at startup.")
|
2018-06-15 00:25:20 +02:00
|
|
|
|
2019-09-03 00:36:42 -04:00
|
|
|
(defvar doom-interactive-mode (not noninteractive)
|
|
|
|
"If non-nil, Emacs is in interactive mode.")
|
|
|
|
|
2019-07-21 03:01:15 +02:00
|
|
|
;;; Directories/files
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-emacs-dir
|
2019-08-06 14:46:15 -04:00
|
|
|
(eval-when-compile (file-truename user-emacs-directory))
|
2019-05-01 19:12:52 -04:00
|
|
|
"The path to the currently loaded .emacs.d directory. Must end with a slash.")
|
2016-10-02 23:25:08 +02:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-core-dir (concat doom-emacs-dir "core/")
|
2019-05-01 19:12:52 -04:00
|
|
|
"The root directory of Doom's core files. Must end with a slash.")
|
2016-10-02 23:25:08 +02:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-modules-dir (concat doom-emacs-dir "modules/")
|
2019-05-01 19:12:52 -04:00
|
|
|
"The root directory for Doom's modules. Must end with a slash.")
|
2018-02-16 02:02:58 -05:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-local-dir
|
2019-10-29 22:36:51 -04:00
|
|
|
(if-let (localdir (getenv "DOOMLOCALDIR"))
|
2019-11-01 15:12:12 -04:00
|
|
|
(expand-file-name (file-name-as-directory localdir))
|
2019-10-29 22:36:51 -04:00
|
|
|
(concat doom-emacs-dir ".local/"))
|
2019-05-01 19:12:52 -04:00
|
|
|
"Root directory for local storage.
|
|
|
|
|
|
|
|
Use this as a storage location for this system's installation of Doom Emacs.
|
|
|
|
These files should not be shared across systems. By default, it is used by
|
|
|
|
`doom-etc-dir' and `doom-cache-dir'. Must end with a slash.")
|
2017-03-16 23:38:22 -04:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-etc-dir (concat doom-local-dir "etc/")
|
2019-05-01 19:12:52 -04:00
|
|
|
"Directory for non-volatile local storage.
|
2017-12-22 14:48:07 -05:00
|
|
|
|
2019-05-01 19:12:52 -04:00
|
|
|
Use this for files that don't change much, like server binaries, external
|
|
|
|
dependencies or long-term shared data. Must end with a slash.")
|
2017-06-11 23:50:50 +02:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-cache-dir (concat doom-local-dir "cache/")
|
2019-05-01 19:12:52 -04:00
|
|
|
"Directory for volatile local storage.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2019-05-01 19:12:52 -04:00
|
|
|
Use this for files that change often, like cache files. Must end with a slash.")
|
2017-04-16 20:36:15 -04:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-docs-dir (concat doom-emacs-dir "docs/")
|
2019-05-01 19:12:52 -04:00
|
|
|
"Where Doom's documentation files are stored. Must end with a slash.")
|
2018-06-17 21:39:40 +02:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-private-dir
|
2019-10-29 22:36:51 -04:00
|
|
|
(if-let (doomdir (getenv "DOOMDIR"))
|
2019-11-01 15:12:12 -04:00
|
|
|
(expand-file-name (file-name-as-directory doomdir))
|
2019-10-29 22:36:51 -04:00
|
|
|
(or (let ((xdgdir
|
|
|
|
(expand-file-name "doom/"
|
|
|
|
(or (getenv "XDG_CONFIG_HOME")
|
|
|
|
"~/.config"))))
|
|
|
|
(if (file-directory-p xdgdir) xdgdir))
|
|
|
|
"~/.doom.d/"))
|
2019-05-01 19:12:52 -04:00
|
|
|
"Where your private configuration is placed.
|
|
|
|
|
|
|
|
Defaults to ~/.config/doom, ~/.doom.d or the value of the DOOMDIR envvar;
|
|
|
|
whichever is found first. Must end in a slash.")
|
2018-04-03 03:07:26 -04:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-autoload-file (concat doom-local-dir "autoloads.el")
|
2019-07-21 15:39:45 +02:00
|
|
|
"Where `doom-reload-core-autoloads' stores its core autoloads.
|
2019-05-01 19:12:52 -04:00
|
|
|
|
|
|
|
This file is responsible for informing Emacs where to find all of Doom's
|
|
|
|
autoloaded core functions (in core/autoload/*.el).")
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-package-autoload-file (concat doom-local-dir "autoloads.pkg.el")
|
2019-07-21 15:39:45 +02:00
|
|
|
"Where `doom-reload-package-autoloads' stores its package autoloads.
|
2019-05-01 19:12:52 -04:00
|
|
|
|
|
|
|
This file is compiled from the autoloads files of all installed packages
|
|
|
|
combined.")
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-env-file (concat doom-local-dir "env")
|
2020-02-19 23:34:16 -05:00
|
|
|
"The location of your envvar file, generated by `doom env`.
|
:boom: Replace exec-path-from-shell w/ 'bin/doom env'
IMPORTANT: This is a breaking update for Mac users, as your shell
environment will no longer be inherited correctly (with the removal of
exec-path-from-shell). The quick fix is: 'bin/doom env refresh'. Also,
the set-env! autodef now does nothing (and is deprecated), be sure to
remove calls to it in your config.
Smaller changes:
+ This update also adds --no-* switches to doom quickstart
+ Includes general improvements to the documentation of several bin/doom
commands.
+ Moves doom/reload* commands to core/autoload/config.el
+ doom/reload-project has been removed (it didn't actually do anything)
The breaking change:
This update adds an "envvar file" to Doom Emacs. This file is generated
by `doom env refresh`, populated with variables scraped from your shell
environment (from both non-interactive and interactive sessions). This
file is then (inexpensively) loaded at startup, if it exists.
+ The file is manually generated with `doom env refresh`.
+ It can be regenerated automatically whenever `doom refresh` is run by
running `doom env enable` (`doom env clear` will reverse this and
delete the env file).
+ `doom quickstart` will ask if you want to auto-generate this envvar
file. You won't need it if you're confident Emacs will always be
started from the correct environment, however.
+ Your env file can be reloaded from a running Emacs session with `M-x
doom/reload-env`. Note: this won't work if the Emacs session you're
running it in doesn't have a correct SHELL set. i.e. don't use this to
create your first env file!
The idea isn't mine -- it's borrowed from Spacemacs -- and was
introduced to me in #1053 by @yurimx. I was impressed with it. Prior to
this, I was unhappy with exec-path-from-shell (no hate to the dev, I
understand its necessity), and 'doom patch-macos' wasn't ideal for mac
users (needed to be reapplied every time you update Emacs). What's more,
many users (even Linux users) had to install exec-path-from-shell
anyway.
This solution suffers from none of their shortcomings. More reliable
than patch-macos, more performant and complete than
exec-path-from-shell, and easily handled by bin/doom.
2019-03-28 00:06:10 -04:00
|
|
|
|
2019-05-01 19:12:52 -04:00
|
|
|
This file contains environment variables scraped from your shell environment,
|
|
|
|
which is loaded at startup (if it exists). This is helpful if Emacs can't
|
2019-05-02 21:54:47 -04:00
|
|
|
\(easily) be launched from the correct shell session (particularly for MacOS
|
2019-05-01 19:12:52 -04:00
|
|
|
users).")
|
:boom: Replace exec-path-from-shell w/ 'bin/doom env'
IMPORTANT: This is a breaking update for Mac users, as your shell
environment will no longer be inherited correctly (with the removal of
exec-path-from-shell). The quick fix is: 'bin/doom env refresh'. Also,
the set-env! autodef now does nothing (and is deprecated), be sure to
remove calls to it in your config.
Smaller changes:
+ This update also adds --no-* switches to doom quickstart
+ Includes general improvements to the documentation of several bin/doom
commands.
+ Moves doom/reload* commands to core/autoload/config.el
+ doom/reload-project has been removed (it didn't actually do anything)
The breaking change:
This update adds an "envvar file" to Doom Emacs. This file is generated
by `doom env refresh`, populated with variables scraped from your shell
environment (from both non-interactive and interactive sessions). This
file is then (inexpensively) loaded at startup, if it exists.
+ The file is manually generated with `doom env refresh`.
+ It can be regenerated automatically whenever `doom refresh` is run by
running `doom env enable` (`doom env clear` will reverse this and
delete the env file).
+ `doom quickstart` will ask if you want to auto-generate this envvar
file. You won't need it if you're confident Emacs will always be
started from the correct environment, however.
+ Your env file can be reloaded from a running Emacs session with `M-x
doom/reload-env`. Note: this won't work if the Emacs session you're
running it in doesn't have a correct SHELL set. i.e. don't use this to
create your first env file!
The idea isn't mine -- it's borrowed from Spacemacs -- and was
introduced to me in #1053 by @yurimx. I was impressed with it. Prior to
this, I was unhappy with exec-path-from-shell (no hate to the dev, I
understand its necessity), and 'doom patch-macos' wasn't ideal for mac
users (needed to be reapplied every time you update Emacs). What's more,
many users (even Linux users) had to install exec-path-from-shell
anyway.
This solution suffers from none of their shortcomings. More reliable
than patch-macos, more performant and complete than
exec-path-from-shell, and easily handled by bin/doom.
2019-03-28 00:06:10 -04:00
|
|
|
|
2019-04-20 02:18:17 -04:00
|
|
|
;;; Custom error types
|
2018-06-20 02:07:12 +02:00
|
|
|
(define-error 'doom-error "Error in Doom Emacs core")
|
2018-06-18 14:47:36 +02:00
|
|
|
(define-error 'doom-hook-error "Error in a Doom startup hook" 'doom-error)
|
2018-06-20 02:07:12 +02:00
|
|
|
(define-error 'doom-autoload-error "Error in an autoloads file" 'doom-error)
|
|
|
|
(define-error 'doom-module-error "Error in a Doom module" 'doom-error)
|
|
|
|
(define-error 'doom-private-error "Error in private config" 'doom-error)
|
|
|
|
(define-error 'doom-package-error "Error with packages" 'doom-error)
|
2018-06-18 14:47:36 +02:00
|
|
|
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
;;
|
2019-04-20 02:18:17 -04:00
|
|
|
;;; Emacs core configuration
|
2016-05-26 18:51:39 -04:00
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; lo', longer logs ahoy, so to reliably locate lapses in doom's logic later
|
2020-01-31 16:43:08 -05:00
|
|
|
(setq message-log-max 8192)
|
|
|
|
|
2019-07-21 04:02:09 +02:00
|
|
|
;; Reduce debug output, well, unless we've asked for it.
|
|
|
|
(setq debug-on-error doom-debug-mode
|
|
|
|
jka-compr-verbose doom-debug-mode)
|
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; Contrary to what many Emacs users have in their configs, you really don't
|
|
|
|
;; need more than this to make UTF-8 the default coding system:
|
2017-05-19 02:54:31 +02:00
|
|
|
(when (fboundp 'set-charset-priority)
|
2019-07-21 04:02:09 +02:00
|
|
|
(set-charset-priority 'unicode)) ; pretty
|
|
|
|
(prefer-coding-system 'utf-8) ; pretty
|
|
|
|
(setq locale-coding-system 'utf-8) ; please
|
2020-03-27 02:33:25 -04:00
|
|
|
;; The clipboard's on Windows could be in an encoding that's wider (or thinner)
|
|
|
|
;; than utf-8, so let Emacs/the OS decide what encoding to use there.
|
2019-03-28 01:46:58 -04:00
|
|
|
(unless IS-WINDOWS
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq selection-coding-system 'utf-8)) ; with sugar on top
|
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; Disable warnings from legacy advice system. They aren't useful, and what can
|
|
|
|
;; we do about them, besides changing packages upstream?
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq ad-redefinition-action 'accept)
|
|
|
|
|
|
|
|
;; Make apropos omnipotent. It's more useful this way.
|
|
|
|
(setq apropos-do-all t)
|
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; A second, case-insensitive pass over `auto-mode-alist' is time wasted, and
|
|
|
|
;; indicates misconfiguration (or that the user needs to stop relying on case
|
|
|
|
;; insensitivity).
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq auto-mode-case-fold nil)
|
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; Less noise at startup. The dashboard/empty scratch buffer is good enough.
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq inhibit-startup-message t
|
|
|
|
inhibit-startup-echo-area-message user-login-name
|
|
|
|
inhibit-default-init t
|
2020-03-27 02:33:25 -04:00
|
|
|
;; Avoid pulling in many packages by starting the scratch buffer in
|
|
|
|
;; `fundamental-mode', rather than, say, `org-mode' or `text-mode'.
|
2019-07-21 04:02:09 +02:00
|
|
|
initial-major-mode 'fundamental-mode
|
|
|
|
initial-scratch-message nil)
|
2020-03-27 02:33:25 -04:00
|
|
|
|
|
|
|
;; Get rid of "For information about GNU Emacs..." message at startup, unless
|
|
|
|
;; we're in a daemon session, where it'll say "Starting Emacs daemon." instead,
|
|
|
|
;; which isn't so bad.
|
|
|
|
(unless (daemonp)
|
|
|
|
(advice-add #'display-startup-echo-area-message :override #'ignore))
|
2019-07-21 04:02:09 +02:00
|
|
|
|
|
|
|
;; Emacs "updates" its ui more often than it needs to, so we slow it down
|
2020-03-27 02:33:25 -04:00
|
|
|
;; slightly from 0.5s:
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq idle-update-delay 1)
|
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; Emacs is essentially one huge security vulnerability, what with all the
|
|
|
|
;; dependencies it pulls in from all corners of the globe. Let's try to be at
|
|
|
|
;; least a little more discerning.
|
2020-03-24 01:29:54 +01:00
|
|
|
(setq gnutls-verify-error (not (getenv "INSECURE"))
|
2020-03-28 02:20:10 +01:00
|
|
|
gnutls-algorithm-priority
|
2020-04-10 23:41:27 -04:00
|
|
|
(when (boundp 'libgnutls-version)
|
2020-04-21 17:08:34 -04:00
|
|
|
(concat "SECURE128:+SECURE192:-VERS-ALL"
|
2020-04-10 23:41:27 -04:00
|
|
|
(if (and (not IS-WINDOWS)
|
|
|
|
(not (version< emacs-version "26.3"))
|
|
|
|
(>= libgnutls-version 30605))
|
2020-04-21 17:08:34 -04:00
|
|
|
":+VERS-TLS1.3")
|
|
|
|
":+VERS-TLS1.2"))
|
2020-03-24 01:29:54 +01:00
|
|
|
;; `gnutls-min-prime-bits' is set based on recommendations from
|
|
|
|
;; https://www.keylength.com/en/4/
|
|
|
|
gnutls-min-prime-bits 3072
|
2019-07-21 04:02:09 +02:00
|
|
|
tls-checktrust gnutls-verify-error
|
2020-04-29 21:54:02 -04:00
|
|
|
;; Emacs is built with `gnutls' by default, so `tls-program' would not be
|
|
|
|
;; used in that case. Otherwise, people have reasons to not go with
|
|
|
|
;; `gnutls', we use `openssl' instead. For more details, see
|
|
|
|
;; https://redd.it/8sykl1
|
2020-03-24 01:29:54 +01:00
|
|
|
tls-program '("openssl s_client -connect %h:%p -CAfile %t -nbio -no_ssl3 -no_tls1 -no_tls1_1 -ign_eof"
|
|
|
|
"gnutls-cli -p %p --dh-bits=3072 --ocsp --x509cafile=%t \
|
|
|
|
--strict-tofu --priority='SECURE192:+SECURE128:-VERS-ALL:+VERS-TLS1.2:+VERS-TLS1.3' %h"
|
2019-07-21 04:02:09 +02:00
|
|
|
;; compatibility fallbacks
|
2020-03-24 01:29:54 +01:00
|
|
|
"gnutls-cli -p %p %h"))
|
2019-07-21 04:02:09 +02:00
|
|
|
|
2020-04-29 21:54:02 -04:00
|
|
|
;; Emacs stores `authinfo' in $HOME and in plain-text. Let's not do that, mkay?
|
2020-03-27 02:33:25 -04:00
|
|
|
;; This file stores usernames, passwords, and other such treasures for the
|
2019-07-21 04:02:09 +02:00
|
|
|
;; aspiring malicious third party.
|
2020-04-29 21:54:02 -04:00
|
|
|
(setq auth-sources (list (concat doom-etc-dir "authinfo.gpg")
|
2019-07-21 04:02:09 +02:00
|
|
|
"~/.authinfo.gpg"))
|
|
|
|
|
2020-01-02 21:13:31 -05:00
|
|
|
;; Don't litter `doom-emacs-dir'. We don't use `no-littering' because it's a
|
|
|
|
;; mote too opinionated for our needs.
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq abbrev-file-name (concat doom-local-dir "abbrev.el")
|
|
|
|
async-byte-compile-log-file (concat doom-etc-dir "async-bytecomp.log")
|
|
|
|
bookmark-default-file (concat doom-etc-dir "bookmarks")
|
2020-01-04 17:10:15 -05:00
|
|
|
custom-file (concat doom-local-dir "custom.el")
|
2019-07-21 04:02:09 +02:00
|
|
|
custom-theme-directory (concat doom-private-dir "themes/")
|
|
|
|
desktop-dirname (concat doom-etc-dir "desktop")
|
|
|
|
desktop-base-file-name "autosave"
|
|
|
|
desktop-base-lock-name "autosave-lock"
|
|
|
|
pcache-directory (concat doom-cache-dir "pcache/")
|
|
|
|
request-storage-directory (concat doom-cache-dir "request")
|
|
|
|
server-auth-dir (concat doom-cache-dir "server/")
|
|
|
|
shared-game-score-directory (concat doom-etc-dir "shared-game-score/")
|
|
|
|
tramp-auto-save-directory (concat doom-cache-dir "tramp-auto-save/")
|
|
|
|
tramp-backup-directory-alist backup-directory-alist
|
|
|
|
tramp-persistency-file-name (concat doom-cache-dir "tramp-persistency.el")
|
|
|
|
url-cache-directory (concat doom-cache-dir "url/")
|
|
|
|
url-configuration-directory (concat doom-etc-dir "url/")
|
|
|
|
gamegrid-user-score-file-directory (concat doom-etc-dir "games/"))
|
2019-10-18 22:07:48 -04:00
|
|
|
|
|
|
|
;; HACK Stop sessions from littering the user directory
|
|
|
|
(defadvice! doom--use-cache-dir-a (session-id)
|
|
|
|
:override #'emacs-session-filename
|
|
|
|
(concat doom-cache-dir "emacs-session." session-id))
|
2019-05-15 18:30:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-07-21 04:02:09 +02:00
|
|
|
;;; Optimizations
|
2019-05-15 18:30:20 -04:00
|
|
|
|
2020-03-27 02:33:25 -04:00
|
|
|
;; Disable bidirectional text rendering for a modest performance boost. I've set
|
2020-04-08 15:29:29 -04:00
|
|
|
;; this to `nil' in the past, but the `bidi-display-reordering's docs say that
|
|
|
|
;; is an undefined state and suggest this to be just as good:
|
2019-12-08 16:11:54 -05:00
|
|
|
(setq-default bidi-display-reordering 'left-to-right
|
|
|
|
bidi-paragraph-direction 'left-to-right)
|
2018-04-03 16:24:15 -04:00
|
|
|
|
2019-07-21 04:02:09 +02:00
|
|
|
;; Reduce rendering/line scan work for Emacs by not rendering cursors or regions
|
|
|
|
;; in non-focused windows.
|
|
|
|
(setq-default cursor-in-non-selected-windows nil)
|
|
|
|
(setq highlight-nonselected-windows nil)
|
2018-04-03 16:24:15 -04:00
|
|
|
|
2019-07-21 04:02:09 +02:00
|
|
|
;; More performant rapid scrolling over unfontified regions. May cause brief
|
2020-04-08 15:29:29 -04:00
|
|
|
;; spells of inaccurate syntax highlighting right after scrolling, which should
|
|
|
|
;; quickly self-correct.
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq fast-but-imprecise-scrolling t)
|
2019-05-15 18:30:20 -04:00
|
|
|
|
2019-07-21 04:02:09 +02:00
|
|
|
;; Resizing the Emacs frame can be a terribly expensive part of changing the
|
2019-09-03 00:42:36 -04:00
|
|
|
;; font. By inhibiting this, we halve startup times, particularly when we use
|
|
|
|
;; fonts that are larger than the system default (which would resize the frame).
|
2019-07-21 04:02:09 +02:00
|
|
|
(setq frame-inhibit-implied-resize t)
|
|
|
|
|
|
|
|
;; Don't ping things that look like domain names.
|
|
|
|
(setq ffap-machine-p-known 'reject)
|
|
|
|
|
2020-03-31 01:00:05 -04:00
|
|
|
;; Font compacting can be terribly expensive, especially for rendering icon
|
2020-04-29 21:54:02 -04:00
|
|
|
;; fonts on Windows. Whether it has a notable affect on Linux and Mac hasn't
|
2020-03-31 01:00:05 -04:00
|
|
|
;; been determined, but we inhibit it there anyway.
|
|
|
|
(setq inhibit-compacting-font-caches t)
|
|
|
|
|
2019-12-06 17:16:34 -05:00
|
|
|
;; Performance on Windows is considerably worse than elsewhere, especially if
|
|
|
|
;; WSL is involved. We'll need everything we can get.
|
2019-07-21 04:02:09 +02:00
|
|
|
(when IS-WINDOWS
|
2020-05-12 04:53:27 -04:00
|
|
|
(setq w32-get-true-file-attributes nil ; slightly faster IO
|
|
|
|
w32-pipe-read-delay 0 ; faster ipc
|
|
|
|
w32-pipe-buffer-size (* 64 1024))) ; read more at a time (was 4K)
|
2019-07-21 04:02:09 +02:00
|
|
|
|
2019-12-06 17:16:34 -05:00
|
|
|
;; Remove command line options that aren't relevant to our current OS; means
|
|
|
|
;; slightly less to process at startup.
|
2019-07-21 04:02:09 +02:00
|
|
|
(unless IS-MAC (setq command-line-ns-option-alist nil))
|
|
|
|
(unless IS-LINUX (setq command-line-x-option-alist nil))
|
2019-07-21 03:01:15 +02:00
|
|
|
|
2020-01-09 19:18:13 -05:00
|
|
|
;; Delete files to trash on macOS, as an extra layer of precaution against
|
|
|
|
;; accidentally deleting wanted files.
|
|
|
|
(setq delete-by-moving-to-trash IS-MAC)
|
|
|
|
|
2019-11-21 14:43:36 -05:00
|
|
|
;; Adopt a sneaky garbage collection strategy of waiting until idle time to
|
2019-12-06 17:16:34 -05:00
|
|
|
;; collect; staving off the collector while the user is working.
|
2020-03-27 19:09:19 -04:00
|
|
|
(when doom-interactive-mode
|
2020-05-12 19:59:14 -04:00
|
|
|
(setq gcmh-idle-delay 5
|
|
|
|
gcmh-high-cons-threshold 16777216 ; 16mb
|
|
|
|
gcmh-verbose doom-debug-mode
|
|
|
|
gc-cons-percentage 0.6)
|
2020-03-27 19:09:19 -04:00
|
|
|
(add-transient-hook! 'pre-command-hook (gcmh-mode +1))
|
|
|
|
(with-eval-after-load 'gcmh
|
2020-05-12 19:59:14 -04:00
|
|
|
(setq gc-cons-percentage 0.1)
|
|
|
|
(add-hook 'focus-out-hook #'gcmh-idle-garbage-collect))
|
2019-07-21 03:01:15 +02:00
|
|
|
|
2019-12-23 00:02:10 -05:00
|
|
|
;; HACK `tty-run-terminal-initialization' is *tremendously* slow for some
|
|
|
|
;; reason. Disabling it completely could have many side-effects, so we
|
2020-03-27 02:33:25 -04:00
|
|
|
;; defer it until later, at which time it (somehow) runs very quickly.
|
2020-04-13 02:07:05 -04:00
|
|
|
(unless (daemonp)
|
|
|
|
(advice-add #'tty-run-terminal-initialization :override #'ignore)
|
|
|
|
(add-hook! 'window-setup-hook
|
|
|
|
(defun doom-init-tty-h ()
|
|
|
|
(advice-remove #'tty-run-terminal-initialization #'ignore)
|
|
|
|
(tty-run-terminal-initialization (selected-frame) nil t))))
|
2019-12-22 23:49:36 -05:00
|
|
|
|
2019-07-21 03:01:15 +02:00
|
|
|
|
2019-05-15 18:30:20 -04:00
|
|
|
;;
|
|
|
|
;;; MODE-local-vars-hook
|
2018-06-15 14:58:31 +02:00
|
|
|
|
2018-09-29 14:57:17 -04:00
|
|
|
;; File+dir local variables are initialized after the major mode and its hooks
|
|
|
|
;; have run. If you want hook functions to be aware of these customizations, add
|
|
|
|
;; them to MODE-local-vars-hook instead.
|
2019-07-26 22:05:26 +02:00
|
|
|
(defun doom-run-local-var-hooks-h ()
|
|
|
|
"Run MODE-local-vars-hook after local variables are initialized."
|
|
|
|
(run-hook-wrapped (intern-soft (format "%s-local-vars-hook" major-mode))
|
|
|
|
#'doom-try-run-hook))
|
|
|
|
(add-hook 'hack-local-variables-hook #'doom-run-local-var-hooks-h)
|
2018-09-28 20:49:58 -04:00
|
|
|
|
2019-10-07 16:10:33 -04:00
|
|
|
;; If the user has disabled `enable-local-variables', then
|
|
|
|
;; `hack-local-variables-hook' is never triggered, so we trigger it at the end
|
|
|
|
;; of `after-change-major-mode-hook':
|
2019-07-26 22:05:26 +02:00
|
|
|
(defun doom-run-local-var-hooks-if-necessary-h ()
|
|
|
|
"Run `doom-run-local-var-hooks-h' if `enable-local-variables' is disabled."
|
|
|
|
(unless enable-local-variables
|
|
|
|
(doom-run-local-var-hooks-h)))
|
2019-07-18 15:27:20 +02:00
|
|
|
(add-hook 'after-change-major-mode-hook
|
2019-07-26 22:05:26 +02:00
|
|
|
#'doom-run-local-var-hooks-if-necessary-h
|
|
|
|
'append)
|
2019-07-18 15:27:20 +02:00
|
|
|
|
2018-04-03 16:24:15 -04:00
|
|
|
|
2018-09-18 11:42:35 -04:00
|
|
|
;;
|
2019-04-20 02:18:17 -04:00
|
|
|
;;; Incremental lazy-loading
|
2018-09-18 11:42:35 -04:00
|
|
|
|
|
|
|
(defvar doom-incremental-packages '(t)
|
|
|
|
"A list of packages to load incrementally after startup. Any large packages
|
|
|
|
here may cause noticable pauses, so it's recommended you break them up into
|
2019-05-01 19:12:52 -04:00
|
|
|
sub-packages. For example, `org' is comprised of many packages, and can be
|
|
|
|
broken up into:
|
2018-09-18 11:42:35 -04:00
|
|
|
|
|
|
|
(doom-load-packages-incrementally
|
|
|
|
'(calendar find-func format-spec org-macs org-compat
|
|
|
|
org-faces org-entities org-list org-pcomplete org-src
|
|
|
|
org-footnote org-macro ob org org-clock org-agenda
|
|
|
|
org-capture))
|
|
|
|
|
|
|
|
This is already done by the lang/org module, however.
|
|
|
|
|
|
|
|
If you want to disable incremental loading altogether, either remove
|
2019-07-18 15:27:20 +02:00
|
|
|
`doom-load-packages-incrementally-h' from `emacs-startup-hook' or set
|
2019-09-03 00:42:36 -04:00
|
|
|
`doom-incremental-first-idle-timer' to nil. Incremental loading does not occur
|
|
|
|
in daemon sessions (they are loaded immediately at startup).")
|
2018-09-18 11:42:35 -04:00
|
|
|
|
2020-03-31 01:00:40 -04:00
|
|
|
(defvar doom-incremental-first-idle-timer 2.0
|
2018-09-18 11:42:35 -04:00
|
|
|
"How long (in idle seconds) until incremental loading starts.
|
|
|
|
|
|
|
|
Set this to nil to disable incremental loading.")
|
|
|
|
|
2020-03-31 01:00:40 -04:00
|
|
|
(defvar doom-incremental-idle-timer 0.75
|
2018-09-18 11:42:35 -04:00
|
|
|
"How long (in idle seconds) in between incrementally loading packages.")
|
|
|
|
|
2020-05-08 16:06:55 -04:00
|
|
|
(defvar doom-incremental-load-immediately (daemonp)
|
|
|
|
"If non-nil, load all incrementally deferred packages immediately at startup.")
|
|
|
|
|
2018-09-18 11:42:35 -04:00
|
|
|
(defun doom-load-packages-incrementally (packages &optional now)
|
|
|
|
"Registers PACKAGES to be loaded incrementally.
|
|
|
|
|
|
|
|
If NOW is non-nil, load PACKAGES incrementally, in `doom-incremental-idle-timer'
|
|
|
|
intervals."
|
|
|
|
(if (not now)
|
2020-05-08 16:06:55 -04:00
|
|
|
(appendq! doom-incremental-packages packages)
|
2019-10-18 22:08:58 -04:00
|
|
|
(while packages
|
|
|
|
(let ((req (pop packages)))
|
|
|
|
(unless (featurep req)
|
2019-06-25 21:38:16 +02:00
|
|
|
(doom-log "Incrementally loading %s" req)
|
|
|
|
(condition-case e
|
2019-08-26 20:36:39 -04:00
|
|
|
(or (while-no-input
|
|
|
|
;; If `default-directory' is a directory that doesn't exist
|
|
|
|
;; or is unreadable, Emacs throws up file-missing errors, so
|
|
|
|
;; we set it to a directory we know exists and is readable.
|
2019-10-18 22:08:58 -04:00
|
|
|
(let ((default-directory doom-emacs-dir)
|
|
|
|
(gc-cons-threshold most-positive-fixnum)
|
|
|
|
file-name-handler-alist)
|
2019-08-26 20:36:39 -04:00
|
|
|
(require req nil t))
|
|
|
|
t)
|
2019-10-18 22:08:58 -04:00
|
|
|
(push req packages))
|
2019-06-25 21:38:16 +02:00
|
|
|
((error debug)
|
|
|
|
(message "Failed to load '%s' package incrementally, because: %s"
|
|
|
|
req e)))
|
2019-10-18 22:08:58 -04:00
|
|
|
(if (not packages)
|
|
|
|
(doom-log "Finished incremental loading")
|
|
|
|
(run-with-idle-timer doom-incremental-idle-timer
|
|
|
|
nil #'doom-load-packages-incrementally
|
|
|
|
packages t)
|
|
|
|
(setq packages nil)))))))
|
2018-09-18 11:42:35 -04:00
|
|
|
|
2019-07-26 22:05:26 +02:00
|
|
|
(defun doom-load-packages-incrementally-h ()
|
|
|
|
"Begin incrementally loading packages in `doom-incremental-packages'.
|
2018-09-18 11:42:35 -04:00
|
|
|
|
|
|
|
If this is a daemon session, load them all immediately instead."
|
2020-05-08 16:06:55 -04:00
|
|
|
(if doom-incremental-load-immediately
|
2019-07-26 22:05:26 +02:00
|
|
|
(mapc #'require (cdr doom-incremental-packages))
|
2020-03-31 01:00:40 -04:00
|
|
|
(when (numberp doom-incremental-first-idle-timer)
|
2019-07-26 22:05:26 +02:00
|
|
|
(run-with-idle-timer doom-incremental-first-idle-timer
|
|
|
|
nil #'doom-load-packages-incrementally
|
|
|
|
(cdr doom-incremental-packages) t))))
|
|
|
|
|
|
|
|
(add-hook 'emacs-startup-hook #'doom-load-packages-incrementally-h)
|
2018-09-18 11:42:35 -04:00
|
|
|
|
|
|
|
|
2018-05-14 18:40:35 +02:00
|
|
|
;;
|
2019-04-20 02:18:17 -04:00
|
|
|
;;; Bootstrap helpers
|
2018-05-14 18:40:35 +02:00
|
|
|
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun doom-display-benchmark-h (&optional return-p)
|
2020-03-27 02:33:25 -04:00
|
|
|
"Display a benchmark including number of packages and modules loaded.
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
If RETURN-P, return the message as a string instead of displaying it."
|
|
|
|
(funcall (if return-p #'format #'message)
|
2019-07-18 15:27:20 +02:00
|
|
|
"Doom loaded %d packages across %d modules in %.03fs"
|
|
|
|
(- (length load-path) (length doom--initial-load-path))
|
2018-06-11 23:18:15 +02:00
|
|
|
(if doom-modules (hash-table-count doom-modules) 0)
|
|
|
|
(or doom-init-time
|
2019-09-03 00:42:36 -04:00
|
|
|
(setq doom-init-time
|
|
|
|
(float-time (time-subtract (current-time) before-init-time))))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2019-12-05 14:52:30 -05:00
|
|
|
(defun doom-initialize (&optional force-p noerror)
|
2019-03-06 21:16:07 -05:00
|
|
|
"Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil).
|
2018-08-08 21:43:50 +02:00
|
|
|
|
2019-12-05 14:52:30 -05:00
|
|
|
The bootstrap process ensures that the essential directories exist, all core
|
|
|
|
packages are installed, `doom-autoload-file' and `doom-package-autoload-file'
|
|
|
|
exist and are loaded, and that `core-packages' is auto-loaded when `package' or
|
|
|
|
`straight' are.
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
The overall load order of Doom is as follows:
|
|
|
|
|
|
|
|
~/.emacs.d/init.el
|
|
|
|
~/.emacs.d/core/core.el
|
|
|
|
~/.doom.d/init.el
|
|
|
|
Module init.el files
|
2019-03-04 20:35:47 -05:00
|
|
|
`doom-before-init-modules-hook'
|
2018-06-11 23:18:15 +02:00
|
|
|
Module config.el files
|
|
|
|
~/.doom.d/config.el
|
2019-03-04 20:35:47 -05:00
|
|
|
`doom-init-modules-hook'
|
2020-04-29 20:19:34 -04:00
|
|
|
`doom-after-init-modules-hook' (`after-init-hook')
|
2018-06-11 23:18:15 +02:00
|
|
|
`emacs-startup-hook'
|
2019-03-04 20:35:47 -05:00
|
|
|
`doom-init-ui-hook'
|
|
|
|
`window-setup-hook'
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
Module load order is determined by your `doom!' block. See `doom-modules-dirs'
|
|
|
|
for a list of all recognized module trees. Order defines precedence (from most
|
|
|
|
to least)."
|
|
|
|
(when (or force-p (not doom-init-p))
|
2019-07-21 03:01:15 +02:00
|
|
|
(setq doom-init-p t)
|
2018-07-09 15:33:31 +02:00
|
|
|
|
2019-07-22 22:28:43 +02:00
|
|
|
;; Reset as much state as possible, so `doom-initialize' can be treated like
|
2020-03-27 02:33:25 -04:00
|
|
|
;; a reset function. e.g. when reloading the config.
|
2019-10-07 16:10:33 -04:00
|
|
|
(setq-default exec-path doom--initial-exec-path
|
|
|
|
load-path doom--initial-load-path
|
|
|
|
process-environment doom--initial-process-environment)
|
2019-04-09 03:43:13 -04:00
|
|
|
|
2019-12-15 23:51:59 -05:00
|
|
|
;; Load shell environment, optionally generated from 'doom env'. No need to
|
|
|
|
;; do so if we're in terminal Emacs, because Emacs will correctly inherit
|
|
|
|
;; your shell environment there.
|
2019-08-23 20:33:30 -04:00
|
|
|
(when (and (or (display-graphic-p)
|
|
|
|
(daemonp))
|
|
|
|
(file-exists-p doom-env-file))
|
|
|
|
(doom-load-envvars-file doom-env-file))
|
|
|
|
|
2019-10-18 22:07:48 -04:00
|
|
|
(require 'core-modules)
|
2019-07-22 22:28:43 +02:00
|
|
|
(let (;; `doom-autoload-file' tells Emacs where to load all its functions
|
|
|
|
;; from. This includes everything in core/autoload/*.el and autoload
|
|
|
|
;; files in enabled modules.
|
2019-12-05 14:52:30 -05:00
|
|
|
(core-autoloads-p (doom-load-autoloads-file doom-autoload-file noerror))
|
2019-07-22 22:28:43 +02:00
|
|
|
;; Loads `doom-package-autoload-file', which loads a concatenated
|
|
|
|
;; package autoloads file which caches `load-path', `auto-mode-alist',
|
|
|
|
;; `Info-directory-list', and `doom-disabled-packages'. A big
|
|
|
|
;; reduction in startup time.
|
2019-12-05 14:52:30 -05:00
|
|
|
(pkg-autoloads-p (doom-load-autoloads-file doom-package-autoload-file noerror)))
|
2019-07-22 22:28:43 +02:00
|
|
|
|
2019-11-04 17:21:25 -05:00
|
|
|
(if (and core-autoloads-p pkg-autoloads-p (not force-p))
|
2019-07-22 22:28:43 +02:00
|
|
|
;; In case we want to use package.el or straight via M-x
|
|
|
|
(progn
|
2019-07-26 20:07:48 +02:00
|
|
|
(with-eval-after-load 'package
|
2019-07-22 22:28:43 +02:00
|
|
|
(require 'core-packages))
|
2019-07-26 20:07:48 +02:00
|
|
|
(with-eval-after-load 'straight
|
|
|
|
(require 'core-packages)
|
2019-07-22 22:28:43 +02:00
|
|
|
(doom-initialize-packages)))
|
|
|
|
|
2019-12-05 14:52:46 -05:00
|
|
|
;; Eagerly load these libraries because we may be in a session that hasn't been
|
|
|
|
;; fully initialized (e.g. where autoloads files haven't been generated or
|
|
|
|
;; `load-path' populated).
|
|
|
|
(mapc (doom-rpartial #'load nil (not doom-debug-mode) 'nosuffix)
|
|
|
|
(file-expand-wildcards (concat doom-core-dir "autoload/*.el")))
|
|
|
|
|
2019-07-22 22:28:43 +02:00
|
|
|
;; Create all our core directories to quell file errors
|
2020-01-26 21:21:06 -05:00
|
|
|
(mapc (doom-rpartial #'make-directory 'parents)
|
|
|
|
(list doom-local-dir
|
|
|
|
doom-etc-dir
|
|
|
|
doom-cache-dir))
|
2019-07-22 22:28:43 +02:00
|
|
|
|
|
|
|
;; Ensure the package management system (and straight) are ready for
|
|
|
|
;; action (and all core packages/repos are installed)
|
|
|
|
(require 'core-packages)
|
|
|
|
(doom-initialize-packages force-p))
|
|
|
|
|
|
|
|
(unless (or (and core-autoloads-p pkg-autoloads-p)
|
2019-12-05 14:52:30 -05:00
|
|
|
noerror)
|
2019-07-22 22:28:43 +02:00
|
|
|
(unless core-autoloads-p
|
2019-09-03 00:42:36 -04:00
|
|
|
(warn "Your Doom core autoloads file is missing"))
|
2019-07-22 22:28:43 +02:00
|
|
|
(unless pkg-autoloads-p
|
2019-09-03 00:42:36 -04:00
|
|
|
(warn "Your package autoloads file is missing"))
|
2019-12-29 18:47:12 -05:00
|
|
|
(signal 'doom-autoload-error (list "Run `bin/doom refresh' to generate them")))
|
|
|
|
|
|
|
|
(when doom-interactive-mode
|
|
|
|
(add-hook 'window-setup-hook #'doom-display-benchmark-h 'append)
|
|
|
|
(add-to-list 'command-switch-alist (cons "--restore" #'doom-restore-session-handler))))
|
2019-09-03 00:42:36 -04:00
|
|
|
t))
|
2019-08-23 20:33:30 -04:00
|
|
|
|
|
|
|
(defun doom-initialize-core ()
|
|
|
|
"Load Doom's core files for an interactive session."
|
|
|
|
(require 'core-keybinds)
|
|
|
|
(require 'core-ui)
|
|
|
|
(require 'core-projects)
|
|
|
|
(require 'core-editor))
|
2017-06-08 11:47:56 +02:00
|
|
|
|
2015-06-04 18:23:21 -04:00
|
|
|
(provide 'core)
|
|
|
|
;;; core.el ends here
|