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
|
|
|
|
2015-06-06 06:40:33 -04:00
|
|
|
;;; Naming conventions:
|
2015-06-04 18:23:21 -04:00
|
|
|
;;
|
2017-06-08 11:47:56 +02:00
|
|
|
;; doom-... public variables or non-interactive functions
|
2017-02-09 04:25:32 -05:00
|
|
|
;; doom--... private anything (non-interactive), not safe for direct use
|
2017-06-08 11:47:56 +02:00
|
|
|
;; doom/... an interactive function; safe for M-x or keybinding
|
2017-11-05 01:23:36 +01:00
|
|
|
;; doom//... an interactive function for managing/maintaining Doom itself
|
2017-02-09 04:25:32 -05:00
|
|
|
;; doom:... an evil operator, motion or command
|
|
|
|
;; doom|... hook function
|
|
|
|
;; doom*... advising functions
|
2017-09-24 15:28:38 +02:00
|
|
|
;; doom@... a hydra command
|
2017-02-23 00:06:12 -05:00
|
|
|
;; ...! a macro or function that configures DOOM
|
2017-09-24 15:28:38 +02:00
|
|
|
;; =... an interactive command that starts an app module
|
2017-02-09 04:25:32 -05:00
|
|
|
;; %... functions used for in-snippet logic
|
2017-06-08 11:47:56 +02:00
|
|
|
;; +... Any of the above but part of a module, e.g. `+emacs-lisp|init-hook'
|
2015-06-04 18:23:21 -04:00
|
|
|
;;
|
2017-02-08 02:02:51 -05:00
|
|
|
;; Autoloaded functions are in core/autoload/*.el and modules/*/*/autoload.el or
|
|
|
|
;; modules/*/*/autoload/*.el.
|
2015-06-04 18:23:21 -04:00
|
|
|
|
2018-01-01 21:20:49 -05:00
|
|
|
(defvar doom-version "2.0.9"
|
2017-02-13 04:53:16 -05:00
|
|
|
"Current version of DOOM emacs.")
|
2016-10-05 12:48:12 +02:00
|
|
|
|
2017-02-04 02:54:37 -05:00
|
|
|
(defvar doom-debug-mode (or (getenv "DEBUG") init-file-debug)
|
2017-02-03 08:00:38 -05:00
|
|
|
"If non-nil, all doom functions will be verbose. Set DEBUG=1 in the command
|
|
|
|
line or use --debug-init to enable this.")
|
2017-01-31 04:31:14 -05:00
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(defvar doom-emacs-dir (eval-when-compile (file-truename user-emacs-directory))
|
2017-02-13 04:53:16 -05:00
|
|
|
"The path to this emacs.d directory.")
|
2016-10-02 23:25:08 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defvar doom-core-dir (concat doom-emacs-dir "core/")
|
2017-02-13 04:53:16 -05:00
|
|
|
"Where essential files are stored.")
|
2016-10-02 23:25:08 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(defvar doom-modules-dir (concat doom-emacs-dir "modules/")
|
2018-02-16 02:02:58 -05:00
|
|
|
"The main directory where Doom modules are stored.")
|
|
|
|
|
2017-01-31 18:58:56 -05:00
|
|
|
(defvar doom-local-dir (concat doom-emacs-dir ".local/")
|
2017-04-16 20:36:15 -04:00
|
|
|
"Root directory for local Emacs files. Use this as permanent storage for files
|
|
|
|
that are safe to share across systems (if this config is symlinked across
|
|
|
|
several computers).")
|
2017-03-16 23:38:22 -04:00
|
|
|
|
2017-12-22 14:48:07 -05:00
|
|
|
(defvar doom-etc-dir (concat doom-local-dir "etc/")
|
2017-12-23 14:30:17 -05:00
|
|
|
"Directory for non-volatile storage.
|
2017-12-22 14:48:07 -05:00
|
|
|
|
2017-12-23 14:30:17 -05:00
|
|
|
Use this for files that don't change much, like servers binaries, external
|
|
|
|
dependencies or long-term shared data.")
|
2017-06-11 23:50:50 +02:00
|
|
|
|
2017-12-22 14:48:07 -05:00
|
|
|
(defvar doom-cache-dir (concat doom-local-dir "cache/")
|
|
|
|
"Directory for volatile storage.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-12-23 14:30:17 -05:00
|
|
|
Use this for files that change often, like cache files.")
|
2017-04-16 20:36:15 -04:00
|
|
|
|
|
|
|
(defvar doom-packages-dir (concat doom-local-dir "packages/")
|
|
|
|
"Where package.el and quelpa plugins (and their caches) are stored.")
|
2016-05-23 06:26:28 -04:00
|
|
|
|
2018-04-03 03:07:26 -04:00
|
|
|
(defvar doom-private-dir
|
|
|
|
(if (file-directory-p "~/.doom.d")
|
|
|
|
"~/.doom.d/"
|
|
|
|
(concat (or (getenv "XDG_CONFIG_HOME")
|
|
|
|
"~/.config")
|
|
|
|
"/doom/"))
|
|
|
|
"TODO")
|
|
|
|
|
2018-03-24 04:40:24 -04:00
|
|
|
(defconst EMACS26+ (not (version< emacs-version "26")))
|
|
|
|
(defconst EMACS27+ (not (version< emacs-version "27")))
|
|
|
|
|
2016-05-26 18:51:39 -04:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;;;
|
2017-01-31 18:59:58 -05:00
|
|
|
;; UTF-8 as the default coding system
|
2017-05-19 02:54:31 +02:00
|
|
|
(when (fboundp 'set-charset-priority)
|
|
|
|
(set-charset-priority 'unicode)) ; pretty
|
2016-09-23 16:13:49 +02:00
|
|
|
(prefer-coding-system 'utf-8) ; pretty
|
2016-06-06 23:53:49 -04:00
|
|
|
(set-terminal-coding-system 'utf-8) ; pretty
|
2017-01-31 18:59:58 -05:00
|
|
|
(set-keyboard-coding-system 'utf-8) ; pretty
|
|
|
|
(set-selection-coding-system 'utf-8) ; perdy
|
|
|
|
(setq locale-coding-system 'utf-8) ; please
|
|
|
|
(setq-default buffer-file-coding-system 'utf-8) ; with sugar on top
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-19 18:11:28 -05:00
|
|
|
(setq-default
|
|
|
|
ad-redefinition-action 'accept ; silence advised function warnings
|
|
|
|
apropos-do-all t ; make `apropos' more useful
|
|
|
|
debug-on-error (and (not noninteractive) doom-debug-mode)
|
2018-02-01 19:50:35 -05:00
|
|
|
ffap-machine-p-known 'reject ; don't ping things that look like domain names
|
2017-03-19 22:50:52 -04:00
|
|
|
idle-update-delay 2 ; update ui less often
|
2017-11-16 18:41:17 +01:00
|
|
|
load-prefer-newer (or noninteractive doom-debug-mode)
|
2017-02-19 18:11:28 -05:00
|
|
|
;; keep the point out of the minibuffer
|
|
|
|
minibuffer-prompt-properties '(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt)
|
2017-04-16 20:36:15 -04:00
|
|
|
;; History & backup settings (save nothing, that's what git is for)
|
2017-02-19 18:11:28 -05:00
|
|
|
auto-save-default nil
|
|
|
|
create-lockfiles nil
|
2017-06-08 11:47:56 +02:00
|
|
|
history-length 500
|
2018-02-01 19:50:35 -05:00
|
|
|
make-backup-files nil ; don't create backup~ files
|
2017-04-16 20:36:15 -04:00
|
|
|
;; files
|
|
|
|
abbrev-file-name (concat doom-local-dir "abbrev.el")
|
|
|
|
auto-save-list-file-name (concat doom-cache-dir "autosave")
|
|
|
|
backup-directory-alist (list (cons "." (concat doom-cache-dir "backup/")))
|
|
|
|
pcache-directory (concat doom-cache-dir "pcache/")
|
2017-11-02 14:17:15 +01:00
|
|
|
mc/list-file (concat doom-etc-dir "mc-lists.el")
|
2017-04-16 20:36:15 -04:00
|
|
|
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/")
|
2017-03-27 13:05:01 -04:00
|
|
|
tramp-backup-directory-alist backup-directory-alist
|
2017-04-16 20:36:15 -04:00
|
|
|
tramp-persistency-file-name (concat doom-cache-dir "tramp-persistency.el")
|
|
|
|
url-cache-directory (concat doom-cache-dir "url/")
|
2017-05-15 11:18:26 +02:00
|
|
|
url-configuration-directory (concat doom-etc-dir "url/"))
|
|
|
|
|
|
|
|
;; move custom defs out of init.el
|
|
|
|
(setq custom-file (concat doom-etc-dir "custom.el"))
|
2018-02-27 22:34:46 -05:00
|
|
|
(load custom-file t t t)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-06-24 02:06:52 +02:00
|
|
|
;; be quiet at startup; don't load or display anything unnecessary
|
2017-12-22 15:21:36 -05:00
|
|
|
(unless noninteractive
|
|
|
|
(advice-add #'display-startup-echo-area-message :override #'ignore)
|
|
|
|
(setq inhibit-startup-message t
|
|
|
|
inhibit-startup-echo-area-message user-login-name
|
|
|
|
inhibit-default-init t
|
|
|
|
initial-major-mode 'fundamental-mode
|
2018-01-29 17:06:20 -05:00
|
|
|
initial-scratch-message nil))
|
2017-02-06 01:25:48 -05:00
|
|
|
|
2017-06-12 00:20:30 +02:00
|
|
|
;; Custom init hooks; clearer than `after-init-hook', `emacs-startup-hook', and
|
|
|
|
;; `window-setup-hook'.
|
|
|
|
(defvar doom-init-hook nil
|
2018-01-07 00:03:34 -05:00
|
|
|
"A list of hooks run when DOOM is initialized, before `doom-post-init-hook'.
|
|
|
|
Use this for essential functionality.")
|
2017-06-12 00:20:30 +02:00
|
|
|
|
|
|
|
(defvar doom-post-init-hook nil
|
|
|
|
"A list of hooks run after DOOM initialization is complete, and after
|
2018-01-07 00:03:34 -05:00
|
|
|
`doom-init-hook'. Use this for extra, non-essential functionality.")
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-06-14 12:17:36 +02:00
|
|
|
(defun doom-try-run-hook (fn hook)
|
|
|
|
"Runs a hook wrapped in a `condition-case-unless-debug' block; its objective
|
|
|
|
is to include more information in the error message, without sacrificing your
|
|
|
|
ability to invoke the debugger in debug mode."
|
|
|
|
(condition-case-unless-debug ex
|
2017-07-27 00:01:55 +02:00
|
|
|
(if noninteractive
|
|
|
|
(quiet! (funcall fn))
|
|
|
|
(funcall fn))
|
2017-06-14 12:17:36 +02:00
|
|
|
('error
|
2017-06-28 01:12:24 +02:00
|
|
|
(lwarn hook :error
|
2018-04-02 06:17:13 -04:00
|
|
|
"%s in '%s' -> %s"
|
|
|
|
(car ex) fn (error-message-string ex))))
|
2017-06-14 12:17:36 +02:00
|
|
|
nil)
|
|
|
|
|
2016-10-02 23:21:47 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;;;
|
2017-06-12 00:20:30 +02:00
|
|
|
;; Initialize
|
2017-06-08 11:47:56 +02:00
|
|
|
(eval-and-compile
|
|
|
|
(defvar doom--file-name-handler-alist file-name-handler-alist)
|
2017-12-22 15:19:08 -05:00
|
|
|
(unless (or after-init-time noninteractive)
|
2018-02-28 17:11:23 -05:00
|
|
|
;; A big contributor to long startup times is the garbage collector, so we
|
|
|
|
;; up its memory threshold, temporarily and reset it later in
|
2017-12-28 19:16:06 -05:00
|
|
|
;; `doom|finalize'.
|
2017-12-22 15:19:08 -05:00
|
|
|
(setq gc-cons-threshold 402653184
|
|
|
|
gc-cons-percentage 0.6
|
|
|
|
file-name-handler-alist nil))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2018-04-03 03:07:26 -04:00
|
|
|
(load (expand-file-name "early-init.el" doom-private-dir) t t)
|
|
|
|
|
2018-02-27 22:24:36 -05:00
|
|
|
(require 'core-packages (concat doom-core-dir "core-packages"))
|
|
|
|
(doom-initialize noninteractive)
|
2017-07-14 18:19:52 +02:00
|
|
|
(load! core-lib)
|
|
|
|
(load! core-os) ; consistent behavior across OSes
|
2017-08-08 16:31:48 +02:00
|
|
|
(unless noninteractive
|
|
|
|
(load! core-ui) ; draw me like one of your French editors
|
|
|
|
(load! core-editor) ; baseline configuration for text editing
|
|
|
|
(load! core-projects) ; making Emacs project-aware
|
2017-12-22 15:21:36 -05:00
|
|
|
(load! core-keybinds)) ; centralized keybind system + which-key
|
2017-06-08 11:47:56 +02:00
|
|
|
|
2018-04-03 03:07:26 -04:00
|
|
|
(load (expand-file-name "init.el" doom-private-dir) t t)
|
|
|
|
|
2018-02-28 17:11:23 -05:00
|
|
|
(defun doom|after-init ()
|
|
|
|
"Run `doom-init-hook' and `doom-post-init-hook', start the Emacs server, and
|
|
|
|
display the loading benchmark."
|
2018-03-02 17:45:15 -05:00
|
|
|
(dolist (hook '(doom-init-hook doom-post-init-hook))
|
|
|
|
(run-hook-wrapped hook #'doom-try-run-hook hook))
|
2018-03-02 23:48:35 -05:00
|
|
|
(unless noninteractive
|
2018-04-03 03:07:26 -04:00
|
|
|
(load (expand-file-name "config.el" doom-private-dir) t t)
|
2018-03-02 23:48:35 -05:00
|
|
|
(when (display-graphic-p)
|
|
|
|
(require 'server)
|
|
|
|
(unless (server-running-p)
|
|
|
|
(server-start)))
|
|
|
|
(message "%s" (doom-packages--benchmark))))
|
2018-02-28 17:11:23 -05:00
|
|
|
|
|
|
|
(defun doom|finalize ()
|
|
|
|
"Resets garbage collection settings to reasonable defaults (if you don't do
|
|
|
|
this, you'll get stuttering and random freezes), and resets
|
|
|
|
`file-name-handler-alist'."
|
2017-12-28 19:16:06 -05:00
|
|
|
(setq gc-cons-threshold 16777216
|
|
|
|
gc-cons-percentage 0.1
|
|
|
|
file-name-handler-alist doom--file-name-handler-alist)
|
|
|
|
t)
|
|
|
|
|
2018-03-28 00:53:50 -04:00
|
|
|
(add-hook! '(emacs-startup-hook doom-reload-hook) #'doom|finalize)
|
|
|
|
(add-hook 'emacs-startup-hook #'doom|after-init))
|
2017-06-08 11:47:56 +02:00
|
|
|
|
2017-12-27 22:48:05 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Emacs fixes/hacks
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Automatic minor modes
|
|
|
|
(defvar doom-auto-minor-mode-alist '()
|
|
|
|
"Alist mapping filename patterns to corresponding minor mode functions, like
|
|
|
|
`auto-mode-alist'. All elements of this alist are checked, meaning you can
|
|
|
|
enable multiple minor modes for the same regexp.")
|
|
|
|
|
|
|
|
(defun doom|enable-minor-mode-maybe ()
|
|
|
|
"Check file name against `doom-auto-minor-mode-alist'."
|
|
|
|
(when buffer-file-name
|
|
|
|
(let ((name buffer-file-name)
|
|
|
|
(remote-id (file-remote-p buffer-file-name))
|
|
|
|
(alist doom-auto-minor-mode-alist))
|
|
|
|
;; Remove backup-suffixes from file name.
|
|
|
|
(setq name (file-name-sans-versions name))
|
|
|
|
;; Remove remote file name identification.
|
|
|
|
(when (and (stringp remote-id)
|
|
|
|
(string-match-p (regexp-quote remote-id) name))
|
|
|
|
(setq name (substring name (match-end 0))))
|
|
|
|
(while (and alist (caar alist) (cdar alist))
|
|
|
|
(if (string-match-p (caar alist) name)
|
|
|
|
(funcall (cdar alist) 1))
|
|
|
|
(setq alist (cdr alist))))))
|
|
|
|
(add-hook 'find-file-hook #'doom|enable-minor-mode-maybe)
|
|
|
|
|
|
|
|
(defun doom*set-indirect-buffer-filename (orig-fn base-buffer name &optional clone)
|
|
|
|
"In indirect buffers, `buffer-file-name' is nil, which can cause problems
|
|
|
|
with functions that require it (like modeline segments)."
|
|
|
|
(let ((file-name (buffer-file-name base-buffer))
|
|
|
|
(buffer (funcall orig-fn base-buffer name clone)))
|
|
|
|
(when (and file-name buffer)
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(unless buffer-file-name
|
|
|
|
(setq buffer-file-name file-name
|
|
|
|
buffer-file-truename (file-truename file-name)))))
|
|
|
|
buffer))
|
|
|
|
(advice-add #'make-indirect-buffer :around #'doom*set-indirect-buffer-filename)
|
|
|
|
|
2015-06-04 18:23:21 -04:00
|
|
|
(provide 'core)
|
|
|
|
;;; core.el ends here
|