doomemacs/core/core.el

182 lines
6.5 KiB
EmacsLisp

;;; core.el --- The heart of the beast
;;; Naming conventions:
;;
;; doom-... public variables or functions (non-interactive)
;; doom--... private anything (non-interactive), not safe for direct use
;; doom/... an interactive function
;; doom:... an evil operator, motion or command
;; doom|... hook function
;; doom*... advising functions
;; doom!... interaction commands exclusively for installing external dependencies
;; @... a macro or function that configures DOOM
;; %... functions used for in-snippet logic
;; +... Any of the above, but part of a module, e.g. +emacs-lisp|init-hook
;;
;; Autoloaded functions are in core/autoload/*.el and modules/*/*/autoload.el or
;; modules/*/*/autoload/*.el.
(when (version< emacs-version "25.1")
(error "DOOM Emacs no longer supports Emacs <25.1! Time to upgrade!"))
;;;
(defvar doom-version "2.0.0"
"Current version of DOOM emacs.")
(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.")
(defvar doom-emacs-dir user-emacs-directory
"The path to this emacs.d directory.")
(defvar doom-core-dir (concat doom-emacs-dir "core/")
"Where essential files are stored.")
(defvar doom-modules-dir (concat doom-emacs-dir "modules/")
"Where configuration modules are stored.")
(defvar doom-local-dir (concat doom-emacs-dir ".local/")
"Untracked directory for local Emacs files, including the cache
(`doom-cache-dir'), packages (`doom-packages-dir') and autoloads file.")
(defvar doom-cache-dir
(concat doom-local-dir "cache/" (system-name) "/")
"Hostname-based directory for temporary files.")
(defvar doom-packages-dir
(concat doom-local-dir "packages/")
"Where package.el and quelpa plugins (and their caches) are kept.")
(defvar doom-autoload-file
(concat doom-local-dir "autoloads.el")
"Location of the autoloads.el, which is generated by `doom/reload-autoloads'
and `doom-initialize-autoloads'.")
(defconst IS-MAC (eq system-type 'darwin))
(defconst IS-LINUX (eq system-type 'gnu/linux))
(defgroup doom nil
""
:group 'emacs)
;;;
;; UTF-8 as the default coding system
(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
;; Configuration
(setq ad-redefinition-accept '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)
idle-update-delay 1 ; update ui less often
;; keep the point out of the minibuffer
minibuffer-prompt-properties '(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt)
;; History & backup settings
auto-save-default nil
auto-save-list-file-name (concat doom-cache-dir "/autosave")
backup-directory-alist (list (cons ".*" (concat doom-cache-dir "/backup/")))
create-lockfiles nil
history-length 1000
make-backup-files nil
vc-make-backup-files nil)
;; be quiet at startup
(advice-add 'display-startup-echo-area-message :override 'ignore)
(setq inhibit-startup-message t
inhibit-startup-echo-area-message user-login-name)
;;;
;; 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 (caar alist) name)
(funcall (cdar alist) 1))
(setq alist (cdr alist))))))
(add-hook 'find-file-hook 'doom|enable-minor-mode-maybe)
;;;
;; Bootstrap
(setq gc-cons-threshold 339430400
gc-cons-percentage 0.6)
(let (file-name-handler-list)
(eval-and-compile
(require 'core-packages (concat doom-core-dir "core-packages")))
(eval-when-compile
(doom-initialize))
(setq load-path (eval-when-compile load-path))
;;; Let 'er rip
(require 'core-lib)
(doom-initialize-autoloads)
(unless noninteractive
(@def-package anaphora
:commands (awhen aif acond awhile))
(@def-package async
:commands (async-start
async-start-process
async-byte-recompile-directory))
(@def-package persistent-soft
:preface (defvar pcache-directory (concat doom-cache-dir "pcache/"))
:commands (persistent-soft-exists-p
persistent-soft-fetch
persistent-soft-flush
persistent-soft-store))
(@def-package ht
:commands (ht-create ht-merge ht-copy ht-select ht-reject ht-select-keys
ht-get ht-keys ht-values ht-items ht-find ht-size
ht-set! ht-update! ht-remove! ht-clear! ht-reject!
ht-map ht-each
ht? ht-contains? ht-equal? ht-empty?
ht->alist ht->plist
ht<-alist ht<-plist
ht ht-amap ht-aeach))
(@def-package smex
:commands (smex smex-major-mode-commands)
:config
(setq smex-save-file (concat doom-cache-dir "/smex-items"))
(smex-initialize))
(require 'core-ui) ; draw me like one of your French editors
(require 'core-popups) ; taming sudden yet inevitable windows
(require 'core-editor) ; baseline configuration for text editing
(require 'core-projects))) ; making Emacs project-aware
(provide 'core)
;;; core.el ends here