doomemacs/core/core.el

197 lines
7.8 KiB
EmacsLisp
Raw Normal View History

;;; core.el --- the heart of the beast -*- lexical-binding: t; -*-
2017-01-17 12:15:48 +08:00
2015-06-06 18:40:33 +08:00
;;; Naming conventions:
2015-06-05 06:23:21 +08:00
;;
;; doom-... public variables or non-interactive functions
;; doom--... private anything (non-interactive), not safe for direct use
;; doom/... an interactive function; safe for M-x or keybinding
;; doom//... an interactive function for managing/maintaining Doom itself
;; doom:... an evil operator, motion or command
;; doom|... hook function
;; doom*... advising functions
;; doom@... a hydra command
;; ...! a macro or function that configures DOOM
;; =... an interactive command that starts an app module
;; %... functions used for in-snippet logic
;; +... Any of the above but part of a module, e.g. `+emacs-lisp|init-hook'
2015-06-05 06:23:21 +08:00
;;
2017-02-08 15:02:51 +08:00
;; Autoloaded functions are in core/autoload/*.el and modules/*/*/autoload.el or
;; modules/*/*/autoload/*.el.
2015-06-05 06:23:21 +08:00
2017-12-17 12:45:25 +08:00
(defvar doom-version "2.0.8"
"Current version of DOOM emacs.")
2016-10-05 18:48:12 +08:00
(defvar doom-debug-mode (or (getenv "DEBUG") init-file-debug)
"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 17:31:14 +08:00
(defvar doom-emacs-dir (file-truename user-emacs-directory)
"The path to this emacs.d directory.")
2017-01-17 12:15:48 +08:00
(defvar doom-core-dir (concat doom-emacs-dir "core/")
"Where essential files are stored.")
2017-01-17 12:15:48 +08:00
(defvar doom-modules-dir (concat doom-emacs-dir "modules/")
"Where configuration modules are stored.")
(defvar doom-local-dir (concat doom-emacs-dir ".local/")
"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).")
(defvar doom-etc-dir (concat doom-local-dir "etc/")
"Directory for non-volatile storage. For volatile story, see `doom-cache-dir'.
Use this for dependencies like servers or config files that are stable (i.e. it
should be unlikely that you need to delete them if something goes wrong).")
(defvar doom-cache-dir (concat doom-local-dir "cache/")
"Directory for volatile storage.
2017-01-17 12:15:48 +08:00
Deleted when `doom/reset' is called. Use this for transient files; on-the-fly
like caches and temporary files. Anything that you don't mind deleting if there
are problems.")
(defvar doom-packages-dir (concat doom-local-dir "packages/")
"Where package.el and quelpa plugins (and their caches) are stored.")
2017-09-29 00:08:20 +08:00
(defvar doom-autoload-file (concat doom-local-dir "autoloads.el")
"Where `doom//reload-autoloads' will generate its autoloads file.")
2017-02-06 14:25:48 +08:00
(defgroup doom nil
2017-06-11 06:59:02 +08:00
"DOOM Emacs, an Emacs configuration for a stubborn, shell-dwelling and
melodramatic ex-vimmer disappointed with the text-editor status quo."
:group 'emacs)
2016-05-27 06:51:39 +08:00
2017-01-17 12:15:48 +08:00
;;;
;; UTF-8 as the default coding system
(when (fboundp 'set-charset-priority)
(set-charset-priority 'unicode)) ; pretty
(prefer-coding-system 'utf-8) ; pretty
(set-terminal-coding-system 'utf-8) ; pretty
(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-17 12:15:48 +08:00
2017-02-20 07:11:28 +08:00
(setq-default
ad-redefinition-action 'accept ; silence advised function warnings
apropos-do-all t ; make `apropos' more useful
compilation-always-kill t ; kill compilation process before starting another
compilation-ask-about-save nil ; save all buffers on `compile'
compilation-scroll-output t
confirm-nonexistent-file-or-buffer t
enable-recursive-minibuffers nil
debug-on-error (and (not noninteractive) doom-debug-mode)
2017-03-20 10:50:52 +08:00
idle-update-delay 2 ; update ui less often
load-prefer-newer (or noninteractive doom-debug-mode)
2017-02-20 07:11:28 +08:00
;; keep the point out of the minibuffer
minibuffer-prompt-properties '(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt)
;; History & backup settings (save nothing, that's what git is for)
2017-02-20 07:11:28 +08:00
auto-save-default nil
create-lockfiles nil
history-length 500
2017-02-20 07:11:28 +08:00
make-backup-files nil
;; 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 21:17:15 +08:00
mc/list-file (concat doom-etc-dir "mc-lists.el")
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/"))
;; move custom defs out of init.el
(setq custom-file (concat doom-etc-dir "custom.el"))
2017-05-16 02:47:14 +08:00
(load custom-file t t)
2017-01-17 12:15:48 +08:00
;; be quiet at startup; don't load or display anything unnecessary
(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
initial-scratch-message nil
mode-line-format nil))
2017-02-06 14:25:48 +08:00
;; Custom init hooks; clearer than `after-init-hook', `emacs-startup-hook', and
;; `window-setup-hook'.
(defvar doom-init-hook nil
"A list of hooks run when DOOM is initialized, before `doom-post-init-hook'.")
(defvar doom-post-init-hook nil
"A list of hooks run after DOOM initialization is complete, and after
`doom-init-hook'.")
2017-01-17 12:15:48 +08: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 06:01:55 +08:00
(if noninteractive
(quiet! (funcall fn))
(funcall fn))
('error
(lwarn hook :error
"%s in '%s' -> %s"
(car ex) fn (error-message-string ex))))
nil)
(defun doom|finalize ()
(unless (or (not after-init-time) noninteractive)
(dolist (hook '(doom-init-hook doom-post-init-hook))
(run-hook-wrapped hook #'doom-try-run-hook hook)))
;; Don't keep gc-cons-threshold too high. It helps to stave off the GC while
;; Emacs starts up, but afterwards it causes stuttering and random freezes. So
;; reset it to a reasonable default.
(setq gc-cons-threshold 16777216
gc-cons-percentage 0.1
2017-11-06 00:16:13 +08:00
file-name-handler-alist doom--file-name-handler-alist)
t)
2016-10-03 05:21:47 +08:00
2017-01-17 12:15:48 +08:00
;;;
;; Initialize
(eval-and-compile
(defvar doom--file-name-handler-alist file-name-handler-alist)
(unless (or after-init-time noninteractive)
(setq gc-cons-threshold 402653184
gc-cons-percentage 0.6
file-name-handler-alist nil))
2017-01-17 12:15:48 +08:00
(require 'cl-lib)
(load (concat doom-core-dir "core-packages") nil t)
(setq load-path (eval-when-compile (doom-initialize t)
(doom-initialize-load-path t))
2017-07-15 00:19:52 +08:00
doom--package-load-path (eval-when-compile doom--package-load-path))
2017-07-15 00:19:52 +08:00
(load! core-lib)
(load! core-os) ; consistent behavior across OSes
(condition-case-unless-debug ex
(require 'autoloads doom-autoload-file t)
('error
(lwarn 'doom-autoloads :warning
"%s in autoloads.el -> %s"
2017-08-08 20:25:36 +08:00
(car ex) (error-message-string ex))))
2017-08-08 22:31:48 +08:00
(unless noninteractive
(load! core-ui) ; draw me like one of your French editors
(load! core-popups) ; taming sudden yet inevitable windows
(load! core-editor) ; baseline configuration for text editing
(load! core-projects) ; making Emacs project-aware
(load! core-keybinds)) ; centralized keybind system + which-key
(add-hook! '(emacs-startup-hook doom-reload-hook)
#'doom|finalize))
2015-06-05 06:23:21 +08:00
(provide 'core)
;;; core.el ends here