2022-07-30 21:49:00 +02:00
|
|
|
;;; doom.el --- the heart of the beast -*- lexical-binding: t; -*-
|
2022-06-18 15:04:12 +02:00
|
|
|
;;
|
|
|
|
;; Author: Henrik Lissner <contact@henrik.io>
|
|
|
|
;; URL: https://github.com/doomemacs/doomemacs
|
|
|
|
;;
|
|
|
|
;; ================= =============== =============== ======== ========
|
|
|
|
;; \\ . . . . . . .\\ //. . . . . . .\\ //. . . . . . .\\ \\. . .\\// . . //
|
|
|
|
;; ||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\/ . . .||
|
|
|
|
;; || . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||
|
|
|
|
;; ||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||
|
|
|
|
;; || . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\ . . . . ||
|
|
|
|
;; ||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\_ . .|. .||
|
|
|
|
;; || . _|| || || || || ||_ . || || . _|| || || || |\ `-_/| . ||
|
|
|
|
;; ||_-' || .|/ || || \|. || `-_|| ||_-' || .|/ || || | \ / |-_.||
|
|
|
|
;; || ||_-' || || `-_|| || || ||_-' || || | \ / | `||
|
|
|
|
;; || `' || || `' || || `' || || | \ / | ||
|
|
|
|
;; || .===' `===. .==='.`===. .===' /==. | \/ | ||
|
|
|
|
;; || .==' \_|-_ `===. .===' _|_ `===. .===' _-|/ `== \/ | ||
|
|
|
|
;; || .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \/ | ||
|
|
|
|
;; || .==' _-' '-__\._-' '-_./__-' `' |. /| | ||
|
|
|
|
;; ||.==' _-' `' | /==.||
|
|
|
|
;; ==' _-' \/ `==
|
|
|
|
;; \ _-' `-_ /
|
|
|
|
;; `'' ``'
|
|
|
|
;;
|
|
|
|
;; These demons are not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This is Doom's heart, where I define all its major constants and variables,
|
|
|
|
;; set its saner global defaults, then prepare Emacs to bootstrap Doom.
|
|
|
|
;;
|
|
|
|
;; The overall load order of Doom is as follows:
|
|
|
|
;;
|
|
|
|
;; $EMACSDIR/early-init.el
|
2022-07-30 21:49:00 +02:00
|
|
|
;; $EMACSDIR/lisp/doom.el
|
|
|
|
;; $EMACSDIR/lisp/doom-start.el
|
2022-06-18 15:04:12 +02:00
|
|
|
;; $DOOMDIR/init.el
|
|
|
|
;; {$DOOMDIR,~/.emacs.d}/modules/*/*/init.el
|
|
|
|
;; `doom-before-init-modules-hook'
|
|
|
|
;; {$DOOMDIR,~/.emacs.d}/modules/*/*/config.el
|
|
|
|
;; `doom-init-modules-hook'
|
|
|
|
;; $DOOMDIR/config.el
|
|
|
|
;; `doom-after-init-modules-hook'
|
|
|
|
;; `after-init-hook'
|
|
|
|
;; `emacs-startup-hook'
|
|
|
|
;; `doom-init-ui-hook'
|
|
|
|
;; `window-setup-hook'
|
|
|
|
;;
|
|
|
|
;;; Code:
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2021-10-09 19:31:21 +02:00
|
|
|
(when (< emacs-major-version 27)
|
2022-09-06 22:28:52 +02:00
|
|
|
(user-error
|
|
|
|
(concat
|
|
|
|
"Detected Emacs " emacs-version ", but Doom requires 27.1 or newer.\n\n"
|
|
|
|
"The version of Emacs in use is located at:\n\n " (car command-line-args) "\n\n"
|
|
|
|
"A guide for installing a newer version of Emacs can be found at:\n\n "
|
|
|
|
(format "https://docs.doomemacs.org/-/install/%s"
|
|
|
|
(cond ((eq system-type 'darwin) "on-macos")
|
|
|
|
((memq system-type '(cygwin windows-nt ms-dos)) "on-windows")
|
|
|
|
("on-linux")))
|
|
|
|
"\n\n"
|
|
|
|
(if (not noninteractive)
|
|
|
|
(concat "If you believe this error is a mistake, run 'doom doctor' on the command line\n"
|
|
|
|
"to diagnose common issues with your config and system.")
|
|
|
|
(concat "Alternatively, either update your $PATH environment variable to include the\n"
|
|
|
|
"path of the desired Emacs executable OR alter the $EMACS environment variable\n"
|
|
|
|
"to specify the exact path or command needed to invoke Emacs. For example:\n\n"
|
|
|
|
(let ((command (ignore-errors (file-name-nondirectory (cadr (member "--load" command-line-args))))))
|
|
|
|
(concat " $ EMACS=/path/to/valid/emacs " command " ...\n"
|
|
|
|
" $ EMACS=\"/Applications/Emacs.app/Contents/MacOS/Emacs\" " command " ...\n"
|
|
|
|
" $ EMACS=\"snap run emacs\" " command " ...\n"))
|
|
|
|
"\nAborting...")))))
|
|
|
|
|
|
|
|
;; Doom needs to be synced/rebuilt if either Doom or Emacs has been
|
|
|
|
;; up/downgraded. This is because byte-code isn't backwards compatible, and many
|
|
|
|
;; packages (including Doom), make in absolute paths into their caches that need
|
|
|
|
;; to be refreshed.
|
|
|
|
(let ((old-version (eval-when-compile emacs-version)))
|
|
|
|
(unless (equal emacs-version old-version)
|
|
|
|
(user-error (concat "Doom was compiled with Emacs %s, but was loaded with %s. Run 'doom sync' to"
|
|
|
|
"recompile it.")
|
|
|
|
emacs-version old-version)))
|
2021-10-09 19:31:21 +02:00
|
|
|
|
|
|
|
;; Remember these variables' initial values, so we can safely reset them at a
|
|
|
|
;; later time, or consult them without fear of contamination.
|
|
|
|
(dolist (var '(exec-path load-path process-environment))
|
|
|
|
(unless (get var 'initial-value)
|
|
|
|
(put var 'initial-value (default-value var))))
|
|
|
|
|
2022-09-06 22:30:07 +02:00
|
|
|
;; Ensure Doom's core libraries are visible for loading
|
|
|
|
(add-to-list 'load-path (file-name-directory load-file-name))
|
|
|
|
|
2022-06-18 15:04:12 +02:00
|
|
|
;; Since Emacs 27, package initialization occurs before `user-init-file' is
|
|
|
|
;; loaded, but after `early-init-file'. Doom handles package initialization, so
|
|
|
|
;; we must prevent Emacs from doing it again.
|
|
|
|
(setq package-enable-at-startup nil)
|
|
|
|
|
2022-09-06 22:30:07 +02:00
|
|
|
;; Custom error types
|
|
|
|
(define-error 'doom-error "An unexpected Doom error")
|
|
|
|
(define-error 'doom-core-error "Unexpected error in Doom's core" 'doom-error)
|
|
|
|
(define-error 'doom-hook-error "Error in a Doom startup hook" 'doom-error)
|
|
|
|
(define-error 'doom-autoload-error "Error in Doom's autoloads file" 'doom-error)
|
|
|
|
(define-error 'doom-user-error "Error caused by user's config or system" 'doom-error)
|
|
|
|
(define-error 'doom-module-error "Error in a Doom module" 'doom-error)
|
|
|
|
(define-error 'doom-package-error "Error with packages" 'doom-error)
|
|
|
|
(define-error 'doom-profile-error "Error while processing profiles" 'doom-error)
|
|
|
|
|
|
|
|
;; Load just the... bear necessities~
|
2022-06-18 15:04:12 +02:00
|
|
|
(require 'cl-lib)
|
|
|
|
(require 'subr-x)
|
2022-09-06 22:30:07 +02:00
|
|
|
;; ...then load *the* one
|
|
|
|
(require 'doom-lib)
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Global constants
|
|
|
|
|
2022-08-12 20:07:08 +02:00
|
|
|
;; DEPRECATED
|
2022-06-18 15:04:12 +02: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)))
|
2022-08-12 20:07:08 +02:00
|
|
|
(defconst IS-BSD (memq system-type '(darwin berkeley-unix gnu/kfreebsd)))
|
|
|
|
|
|
|
|
(unless (featurep 'doom)
|
|
|
|
;; Since `system-configuration-features's docs state not to rely on it to test
|
|
|
|
;; for features, let's give users an easier way to detect them.
|
|
|
|
(if (bound-and-true-p module-file-suffix)
|
|
|
|
(push 'dynamic-modules features))
|
|
|
|
(if (fboundp #'json-parse-string)
|
|
|
|
(push 'jansson features))
|
|
|
|
;; `native-compile' exists whether or not it is functional (e.g. libgcc is
|
|
|
|
;; available or not). This seems silly, so pretend it doesn't exist if it
|
|
|
|
;; isn't available.
|
|
|
|
(if (featurep 'native-compile)
|
|
|
|
(if (not (native-comp-available-p))
|
|
|
|
(delq 'native-compile features)))
|
|
|
|
|
|
|
|
;; DEPRECATED remove in v3
|
|
|
|
(defconst EMACS28+ (> emacs-major-version 27))
|
|
|
|
(defconst EMACS29+ (> emacs-major-version 28))
|
|
|
|
;; DEPRECATED remove in v3
|
|
|
|
(defconst MODULES (featurep 'dynamic-modules))
|
2022-08-13 21:27:11 +02:00
|
|
|
(defconst NATIVECOMP (featurep 'native-compile)))
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Cross-platform fixes
|
|
|
|
|
|
|
|
(when IS-WINDOWS
|
|
|
|
(when-let (realhome
|
|
|
|
;; Fix HOME on Windows, where it's not normally defined (though
|
|
|
|
;; many unix tools expect it).
|
|
|
|
(and (null (getenv-internal "HOME"))
|
|
|
|
(getenv "USERPROFILE")))
|
|
|
|
(setenv "HOME" realhome)
|
|
|
|
(setq abbreviated-home-dir nil)))
|
2021-10-09 19:31:21 +02:00
|
|
|
|
|
|
|
|
2020-05-25 02:20:26 -04:00
|
|
|
;;
|
2022-06-18 15:04:12 +02:00
|
|
|
;;; Core variables
|
2020-05-25 02:20:26 -04:00
|
|
|
|
2021-10-09 19:31:21 +02:00
|
|
|
(defgroup doom nil
|
|
|
|
"An Emacs framework for the stubborn martian hacker."
|
|
|
|
:link '(url-link "https://doomemacs.org"))
|
2019-09-03 00:42:36 -04:00
|
|
|
|
2022-03-20 23:56:06 +01:00
|
|
|
(defconst doom-version "3.0.0-dev"
|
2021-10-09 19:31:21 +02:00
|
|
|
"Current version of Doom Emacs core.")
|
2020-12-01 19:33:55 -05:00
|
|
|
|
2022-08-03 18:28:29 +02:00
|
|
|
(defconst doom-modules-version "22.08.0-dev"
|
2022-03-20 23:56:06 +01:00
|
|
|
"Current version of Doom Emacs.")
|
|
|
|
|
2019-10-30 00:02:04 -04:00
|
|
|
|
2019-09-03 00:42:36 -04:00
|
|
|
;;
|
2020-12-01 19:33:55 -05:00
|
|
|
;;; Directory variables
|
2019-05-01 19:12:52 -04:00
|
|
|
|
2020-12-01 19:33:55 -05:00
|
|
|
(defconst doom-emacs-dir 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
|
|
|
|
2022-08-02 20:19:03 +02:00
|
|
|
(defconst doom-core-dir (file-name-directory load-file-name)
|
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
|
|
|
|
2022-07-29 12:23:42 +02:00
|
|
|
(defconst doom-modules-dir (expand-file-name "modules/" doom-emacs-dir)
|
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
|
|
|
|
2022-08-13 21:27:11 +02:00
|
|
|
(defconst doom-user-dir
|
2022-07-27 22:25:08 +02:00
|
|
|
(if-let (doomdir (getenv-internal "DOOMDIR"))
|
|
|
|
(expand-file-name (file-name-as-directory doomdir))
|
|
|
|
(or (let ((xdgdir
|
|
|
|
(expand-file-name "doom/"
|
|
|
|
(or (getenv-internal "XDG_CONFIG_HOME")
|
|
|
|
"~/.config"))))
|
|
|
|
(if (file-directory-p xdgdir) xdgdir))
|
|
|
|
"~/.doom.d/"))
|
|
|
|
"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.")
|
|
|
|
|
|
|
|
(defconst doom-profile
|
|
|
|
(if-let (profile (getenv-internal "DOOMPROFILE"))
|
|
|
|
;; DEPRECATED Use `string-search' once 27 support is dropped
|
|
|
|
(if (string-match-p "@" profile)
|
|
|
|
profile
|
|
|
|
(concat profile "@latest"))
|
|
|
|
;; TODO Restore this when profile system is complete
|
|
|
|
;; "default@latest"
|
|
|
|
)
|
|
|
|
"The name of the active profile.")
|
|
|
|
|
|
|
|
;; TODO Use me
|
|
|
|
(defconst doom-profiles-file
|
|
|
|
(expand-file-name "profiles.el" user-emacs-directory)
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
(defconst doom-profiles-dir
|
|
|
|
(if-let (profilesdir (getenv-internal "DOOMPROFILESDIR"))
|
|
|
|
(expand-file-name "./" profilesdir)
|
|
|
|
(expand-file-name "profiles/" doom-emacs-dir))
|
|
|
|
"Where Doom stores its profiles.
|
|
|
|
|
|
|
|
Profiles are essentially snapshots of Doom Emacs environments. Every time you
|
|
|
|
update or sync, you create a new generation of a profile (which can be easily
|
|
|
|
rolled back or switched between with the DOOMPROFILE envvar). Must end in a
|
|
|
|
slash.")
|
|
|
|
|
|
|
|
(defconst doom-profile-dir
|
|
|
|
(expand-file-name (concat (or doom-profile "default@latest") "/")
|
|
|
|
doom-profiles-dir)
|
|
|
|
"The path to the current, active profile.
|
|
|
|
|
|
|
|
Must end in a slash.")
|
|
|
|
|
|
|
|
(defconst doom-profile-data-dir
|
|
|
|
(expand-file-name "data/" doom-profile-dir)
|
|
|
|
"Where file storage/servers for the current, active profile is kept.
|
|
|
|
|
|
|
|
Use this for long-living files that contain shared data that the user would
|
|
|
|
reasonably want to keep, and/or are required for Emacs to function correctly.
|
|
|
|
Must end in a slash.")
|
|
|
|
|
|
|
|
(defconst doom-profile-cache-dir
|
|
|
|
(expand-file-name "cache/" doom-profile-dir)
|
|
|
|
"Where file caches for the current, active profile is kept.
|
|
|
|
|
|
|
|
Use this for non-essential data files that, when deleted, won't cause breakage
|
|
|
|
or misbehavior, and can be restored. This includes server binaries or programs
|
|
|
|
downloaded/installed by packages. Must end in a slash.")
|
|
|
|
|
|
|
|
(defconst doom-profile-init-file
|
|
|
|
(expand-file-name "init.el" doom-profile-dir)
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; DEPRECATED file/directory vars
|
|
|
|
|
2019-11-01 15:12:12 -04:00
|
|
|
(defconst doom-local-dir
|
2021-10-09 19:31:21 +02:00
|
|
|
(if-let (localdir (getenv-internal "DOOMLOCALDIR"))
|
|
|
|
(expand-file-name (file-name-as-directory localdir))
|
2022-07-27 22:25:08 +02:00
|
|
|
(if doom-profile
|
2022-07-28 12:39:09 +02:00
|
|
|
doom-profile-dir
|
|
|
|
(expand-file-name ".local/" doom-emacs-dir)))
|
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.
|
2020-10-11 16:22:57 -04:00
|
|
|
|
2019-05-01 19:12:52 -04:00
|
|
|
These files should not be shared across systems. By default, it is used by
|
2022-08-14 18:10:01 +02:00
|
|
|
`doom-data-dir' and `doom-cache-dir'. Must end with a slash.")
|
2017-03-16 23:38:22 -04:00
|
|
|
|
2022-08-14 18:10:01 +02:00
|
|
|
(defconst doom-data-dir
|
2022-07-27 22:25:08 +02:00
|
|
|
(if doom-profile
|
|
|
|
doom-profile-data-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
|
|
|
|
2022-07-27 22:25:08 +02:00
|
|
|
(defconst doom-cache-dir
|
|
|
|
(if doom-profile
|
|
|
|
doom-profile-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
|
|
|
|
2020-10-28 05:17:02 -04:00
|
|
|
(defconst doom-autoloads-file
|
2022-07-27 22:25:08 +02:00
|
|
|
(if doom-profile
|
|
|
|
doom-profile-init-file
|
|
|
|
(concat doom-local-dir "autoloads." emacs-version ".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
|
2022-07-30 21:49:00 +02:00
|
|
|
autoloaded core functions (in lisp/lib/*.el).")
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-07-27 22:25:08 +02:00
|
|
|
(defconst doom-env-file
|
|
|
|
(if doom-profile
|
|
|
|
(expand-file-name "env" doom-profile-dir)
|
|
|
|
(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
|
|
|
|
2020-12-01 19:33:55 -05:00
|
|
|
|
2022-08-13 21:27:11 +02:00
|
|
|
;;
|
|
|
|
;;; Legacy support
|
|
|
|
|
|
|
|
(define-obsolete-variable-alias 'doom-private-dir 'doom-user-dir "3.0.0")
|
2022-08-14 18:10:01 +02:00
|
|
|
(define-obsolete-variable-alias 'doom-etc-dir 'doom-data-dir "3.0.0")
|
2022-08-13 21:27:11 +02:00
|
|
|
|
|
|
|
(make-obsolete-variable 'EMACS28+ "Use (>= emacs-major-version 28) instead" "3.0.0")
|
|
|
|
(make-obsolete-variable 'EMACS29+ "Use (>= emacs-major-version 29) instead" "3.0.0")
|
|
|
|
(make-obsolete-variable 'MODULES "Use (featurep 'dynamic-modules) instead" "3.0.0")
|
|
|
|
(make-obsolete-variable 'NATIVECOMP "Use (featurep 'native-compile) instead" "3.0.0")
|
|
|
|
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
;;
|
2020-12-01 19:33:55 -05:00
|
|
|
;;; Native Compilation support (http://akrl.sdf.org/gccemacs.html)
|
2016-05-26 18:51:39 -04:00
|
|
|
|
2022-08-12 20:07:08 +02:00
|
|
|
(when (featurep 'native-compile)
|
2022-09-06 19:26:33 +02:00
|
|
|
;; Enable deferred compilation and disable ahead-of-time compilation, so we
|
|
|
|
;; don't bog down the install process with an excruciatingly long compile
|
|
|
|
;; times. It will mean more CPU time at runtime, but given its asynchronosity,
|
|
|
|
;; this is acceptable.
|
|
|
|
(setq native-comp-deferred-compilation t
|
|
|
|
straight-disable-native-compile t)
|
|
|
|
|
|
|
|
;; Suppress compiler warnings, to avoid inundating users will popups. They
|
|
|
|
;; don't cause breakage, so it's not worth dedicating screen estate to them.
|
|
|
|
(setq native-comp-async-report-warnings-errors init-file-debug
|
|
|
|
native-comp-warning-on-missing-source init-file-debug)
|
|
|
|
|
2022-06-18 15:04:12 +02:00
|
|
|
;; Don't store eln files in ~/.emacs.d/eln-cache (where they can easily be
|
|
|
|
;; deleted by 'doom upgrade').
|
2022-08-14 00:45:03 +02:00
|
|
|
;; REVIEW Use `startup-redirect-eln-cache' when 28 support is dropped
|
2022-08-14 20:44:16 +02:00
|
|
|
(add-to-list 'native-comp-eln-load-path (expand-file-name "eln/" doom-cache-dir)))
|
2020-12-01 19:33:55 -05:00
|
|
|
|
|
|
|
|
2020-12-01 13:43:51 -05:00
|
|
|
;;
|
2022-07-29 12:22:33 +02:00
|
|
|
;;; Don't litter `doom-emacs-dir'/$HOME
|
2020-12-01 13:43:51 -05:00
|
|
|
|
2022-06-18 00:37:46 +02:00
|
|
|
;; I change `user-emacs-directory' because many packages (even built-in ones)
|
|
|
|
;; abuse it to build paths for storage/cache files (instead of correctly using
|
|
|
|
;; `locate-user-emacs-file'). This change ensures that said data files are never
|
|
|
|
;; saved to the root of your emacs directory *and* saves us the trouble setting
|
|
|
|
;; a million directory/file variables.
|
|
|
|
(setq user-emacs-directory doom-cache-dir)
|
|
|
|
|
|
|
|
;; ...However, this may surprise packages (and users) that read
|
|
|
|
;; `user-emacs-directory' expecting to find the location of your Emacs config,
|
|
|
|
;; such as server.el!
|
|
|
|
(setq server-auth-dir (expand-file-name "server/" doom-emacs-dir))
|
|
|
|
|
|
|
|
;; Packages with file/dir settings that don't use `user-emacs-directory' or
|
|
|
|
;; `locate-user-emacs-file' to initialize will need to set explicitly, to stop
|
|
|
|
;; them from littering in ~/.emacs.d/.
|
|
|
|
(setq desktop-dirname (expand-file-name "desktop" doom-cache-dir)
|
|
|
|
pcache-directory (expand-file-name "pcache/" doom-cache-dir))
|
|
|
|
|
|
|
|
;; Allow the user to store custom.el-saved settings and themes in their Doom
|
|
|
|
;; config (e.g. ~/.doom.d/).
|
2022-08-13 21:27:11 +02:00
|
|
|
(setq custom-file (expand-file-name "custom.el" doom-user-dir))
|
2022-06-18 00:37:46 +02:00
|
|
|
|
2022-07-29 12:22:33 +02:00
|
|
|
;; By default, Emacs stores `authinfo' in $HOME and in plain-text. Let's not do
|
|
|
|
;; that, mkay? This file stores usernames, passwords, and other treasures for
|
|
|
|
;; the aspiring malicious third party. You'll need a GPG setup though.
|
2022-08-14 18:10:01 +02:00
|
|
|
(setq auth-sources (list (concat doom-data-dir "authinfo.gpg")
|
2022-07-29 12:22:33 +02:00
|
|
|
"~/.authinfo.gpg"))
|
|
|
|
|
2022-06-18 00:37:46 +02:00
|
|
|
(define-advice en/disable-command (:around (fn &rest args) write-to-data-dir)
|
|
|
|
"Write saved safe-local-variables to `custom-file' instead.
|
|
|
|
|
|
|
|
Otherwise, `en/disable-command' (in novice.el.gz) is hardcoded to write them to
|
|
|
|
`user-init-file')."
|
|
|
|
(let ((user-init-file custom-file))
|
2021-08-04 01:18:06 -04:00
|
|
|
(apply fn args)))
|
2020-06-13 16:09:26 -04:00
|
|
|
|
2020-08-17 21:46:54 -04:00
|
|
|
|
2021-10-09 19:31:21 +02:00
|
|
|
;;
|
2022-06-18 15:04:12 +02:00
|
|
|
;;; Runtime/startup optimizations
|
2019-05-15 18:30:20 -04:00
|
|
|
|
2022-06-18 15:04:12 +02:00
|
|
|
;; A second, case-insensitive pass over `auto-mode-alist' is time wasted and
|
|
|
|
;; indicates misconfiguration.
|
2020-12-01 19:33:55 -05:00
|
|
|
(setq auto-mode-case-fold nil)
|
|
|
|
|
2021-07-11 10:48:07 -04:00
|
|
|
;; Disable bidirectional text scanning 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
|
|
|
|
2020-08-04 14:58:13 -04:00
|
|
|
;; Disabling the BPA makes redisplay faster, but might produce incorrect display
|
|
|
|
;; reordering of bidirectional text with embedded parentheses and other bracket
|
|
|
|
;; characters whose 'paired-bracket' Unicode property is non-nil.
|
|
|
|
(setq bidi-inhibit-bpa t) ; Emacs 27 only
|
|
|
|
|
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
|
|
|
|
2020-12-01 19:33:55 -05:00
|
|
|
;; Don't ping things that look like domain names.
|
|
|
|
(setq ffap-machine-p-known 'reject)
|
|
|
|
|
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)
|
|
|
|
|
2021-04-25 18:35:49 -04:00
|
|
|
;; Emacs "updates" its ui more often than it needs to, so slow it down slightly
|
|
|
|
(setq idle-update-delay 1.0) ; default is 0.5
|
2019-07-21 04:02:09 +02:00
|
|
|
|
2020-03-31 01:00:05 -04:00
|
|
|
;; Font compacting can be terribly expensive, especially for rendering icon
|
2020-08-20 03:35:29 -04:00
|
|
|
;; fonts on Windows. Whether disabling it has a notable affect on Linux and Mac
|
2022-06-18 15:04:12 +02:00
|
|
|
;; hasn't been determined, but do it anyway, just in case. This increases memory
|
|
|
|
;; usage, however!
|
2020-03-31 01:00:05 -04:00
|
|
|
(setq inhibit-compacting-font-caches t)
|
|
|
|
|
2021-09-29 13:59:11 +02:00
|
|
|
;; PGTK builds only: this timeout adds latency to frame operations, like
|
|
|
|
;; `make-frame-invisible', which are frequently called without a guard because
|
|
|
|
;; it's inexpensive in non-PGTK builds. Lowering the timeout from the default
|
|
|
|
;; 0.1 should make childframes and packages that manipulate them (like `lsp-ui',
|
|
|
|
;; `company-box', and `posframe') feel much snappier. See emacs-lsp/lsp-ui#613.
|
|
|
|
(setq pgtk-wait-for-event-timeout 0.001)
|
|
|
|
|
2021-04-18 22:56:52 -04:00
|
|
|
;; Increase how much is read from processes in a single chunk (default is 4kb).
|
2021-04-25 18:35:49 -04:00
|
|
|
;; This is further increased elsewhere, where needed (like our LSP module).
|
2021-04-18 22:56:52 -04:00
|
|
|
(setq read-process-output-max (* 64 1024)) ; 64kb
|
|
|
|
|
2021-01-07 01:42:38 -05:00
|
|
|
;; Introduced in Emacs HEAD (b2f8c9f), this inhibits fontification while
|
2021-04-25 18:35:49 -04:00
|
|
|
;; receiving input, which should help a little with scrolling performance.
|
2021-01-07 01:42:38 -05:00
|
|
|
(setq redisplay-skip-fontification-on-input t)
|
|
|
|
|
2020-07-25 17:52:55 -04:00
|
|
|
;; Performance on Windows is considerably worse than elsewhere. We'll need
|
|
|
|
;; everything we can get.
|
2021-10-09 19:31:21 +02:00
|
|
|
(when (boundp 'w32-get-true-file-attributes)
|
2020-07-25 17:52:55 -04:00
|
|
|
(setq w32-get-true-file-attributes nil ; decrease file IO workload
|
2021-04-25 18:35:49 -04:00
|
|
|
w32-pipe-read-delay 0 ; faster IPC
|
2022-06-18 15:04:12 +02:00
|
|
|
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.
|
2021-10-09 19:31:21 +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
|
|
|
|
2019-12-23 00:02:10 -05:00
|
|
|
;; HACK `tty-run-terminal-initialization' is *tremendously* slow for some
|
2020-08-20 03:35:29 -04:00
|
|
|
;; reason; inexplicably doubling startup time for terminal Emacs. Keeping
|
2021-04-25 18:35:49 -04:00
|
|
|
;; it disabled will have nasty side-effects, so we simply delay it instead,
|
|
|
|
;; and invoke it later, at which point it runs quickly; how mysterious!
|
2022-07-29 12:24:25 +02:00
|
|
|
(unless (or (daemonp) init-file-debug)
|
2020-04-13 02:07:05 -04:00
|
|
|
(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
|
|
|
|
2022-06-18 15:04:12 +02:00
|
|
|
;; Shave seconds off startup time by starting the scratch buffer in
|
|
|
|
;; `fundamental-mode', rather than, say, `org-mode' or `text-mode', which pull
|
|
|
|
;; in a ton of packages. `doom/open-scratch-buffer' provides a better scratch
|
|
|
|
;; buffer anyway.
|
|
|
|
(setq initial-major-mode 'fundamental-mode
|
|
|
|
initial-scratch-message nil)
|
|
|
|
|
2019-07-21 03:01:15 +02:00
|
|
|
|
2020-12-01 19:33:55 -05:00
|
|
|
;;
|
2022-06-18 15:04:12 +02:00
|
|
|
;;; Reasonable, global defaults
|
|
|
|
|
|
|
|
;; Contrary to what many Emacs users have in their configs, you don't need more
|
|
|
|
;; than this to make UTF-8 the default coding system:
|
|
|
|
(set-language-environment "UTF-8")
|
|
|
|
;; ...but `set-language-environment' also sets `default-input-method', which is
|
|
|
|
;; a step too opinionated.
|
|
|
|
(setq default-input-method nil)
|
|
|
|
;; ...And the clipboard on Windows could be in a wider encoding (UTF-16), so
|
|
|
|
;; leave Emacs to its own devices.
|
|
|
|
(unless IS-WINDOWS
|
|
|
|
(setq selection-coding-system 'utf-8))
|
2020-12-01 19:33:55 -05:00
|
|
|
|
2022-06-18 15:04:12 +02:00
|
|
|
;; Disable warnings from the legacy advice API. They aren't actionable or
|
|
|
|
;; useful, and often come from third party packages.
|
2021-10-09 19:31:21 +02:00
|
|
|
(setq ad-redefinition-action 'accept)
|
2018-06-15 14:58:31 +02:00
|
|
|
|
2022-08-08 17:51:29 +02:00
|
|
|
;; Ignore warnings about "existing variables being aliased". Otherwise the user
|
|
|
|
;; gets very intrusive popup warnings about our (intentional) uses of
|
|
|
|
;; defvaralias.
|
|
|
|
(after! warnings
|
|
|
|
(add-to-list 'warning-suppress-types '(defvaralias)))
|
|
|
|
|
2022-06-18 15:04:12 +02:00
|
|
|
;; Reduce debug output unless we've asked for it.
|
2021-10-09 19:31:21 +02:00
|
|
|
(setq debug-on-error init-file-debug
|
|
|
|
jka-compr-verbose init-file-debug)
|
2020-08-02 16:28:56 -04:00
|
|
|
|
2022-07-29 12:22:33 +02:00
|
|
|
;; Get rid of "For information about GNU Emacs..." message at startup. It's
|
|
|
|
;; redundant with our dashboard. However, in daemon sessions it says "Starting
|
|
|
|
;; Emacs daemon." instead, which is fine.
|
2021-10-09 19:31:21 +02:00
|
|
|
(unless (daemonp)
|
|
|
|
(advice-add #'display-startup-echo-area-message :override #'ignore))
|
2018-09-28 20:49:58 -04:00
|
|
|
|
2021-10-09 19:31:21 +02:00
|
|
|
;; Reduce *Message* noise at startup. An empty scratch buffer (or the dashboard)
|
|
|
|
;; is more than enough.
|
|
|
|
(setq inhibit-startup-screen t
|
|
|
|
inhibit-startup-echo-area-message user-login-name
|
2022-06-18 15:04:12 +02:00
|
|
|
inhibit-default-init t)
|
2021-10-10 18:14:41 +02:00
|
|
|
|
2022-06-18 15:04:12 +02: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 a
|
|
|
|
;; *little* more discerning.
|
|
|
|
(setq gnutls-verify-error noninteractive
|
|
|
|
gnutls-algorithm-priority
|
|
|
|
(when (boundp 'libgnutls-version)
|
|
|
|
(concat "SECURE128:+SECURE192:-VERS-ALL"
|
|
|
|
(if (and (not IS-WINDOWS)
|
|
|
|
(>= libgnutls-version 30605))
|
|
|
|
":+VERS-TLS1.3")
|
|
|
|
":+VERS-TLS1.2"))
|
|
|
|
;; `gnutls-min-prime-bits' is set based on recommendations from
|
|
|
|
;; https://www.keylength.com/en/4/
|
|
|
|
gnutls-min-prime-bits 3072
|
|
|
|
tls-checktrust gnutls-verify-error
|
|
|
|
;; Emacs is built with gnutls.el by default, so `tls-program' won't
|
|
|
|
;; typically be used, but in the odd case that it does, we ensure a more
|
|
|
|
;; secure default for it (falling back to `openssl' if absolutely
|
|
|
|
;; necessary). See https://redd.it/8sykl1 for details.
|
|
|
|
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"
|
|
|
|
;; compatibility fallbacks
|
|
|
|
"gnutls-cli -p %p %h"))
|
2017-06-08 11:47:56 +02:00
|
|
|
|
2022-07-30 21:49:00 +02:00
|
|
|
(provide 'doom)
|
|
|
|
;;; doom.el ends here
|