Minor refactors across the board

This commit is contained in:
Henrik Lissner 2019-10-07 16:10:33 -04:00
parent 774ca43e32
commit ddce674a6c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 89 additions and 79 deletions

View file

@ -10,10 +10,9 @@
":"; exec $EMACS --script "$0" -- "$@" ":"; exec $EMACS --script "$0" -- "$@"
":"; exit 0 ":"; exit 0
(setq user-emacs-directory (defconst user-emacs-directory
(or (getenv "EMACSDIR") (or (getenv "EMACSDIR")
(expand-file-name "../" (file-name-directory (file-truename load-file-name))))) (expand-file-name "../" (file-name-directory (file-truename load-file-name)))))
(defun usage () (defun usage ()
(with-temp-buffer (with-temp-buffer

View file

@ -313,7 +313,8 @@ If N and M = 1, there's no benefit to using this macro over `remove-hook'.
\(fn HOOKS &rest [SYM VAL]...)" \(fn HOOKS &rest [SYM VAL]...)"
(declare (indent 1)) (declare (indent 1))
(macroexp-progn (macroexp-progn
(cl-loop for (_var _val hook fn) in (doom--setq-hook-fns hooks vars 'singles) (cl-loop for (_var _val hook fn)
in (doom--setq-hook-fns hooks vars 'singles)
collect `(remove-hook ',hook #',fn)))) collect `(remove-hook ',hook #',fn))))
(defmacro load! (filename &optional path noerror) (defmacro load! (filename &optional path noerror)
@ -325,20 +326,22 @@ directory path). If omitted, the lookup is relative to either `load-file-name',
`byte-compile-current-file' or `buffer-file-name' (checked in that order). `byte-compile-current-file' or `buffer-file-name' (checked in that order).
If NOERROR is non-nil, don't throw an error if the file doesn't exist." If NOERROR is non-nil, don't throw an error if the file doesn't exist."
(unless path (let* ((path (or path
(setq path (or (dir!) (dir!)
(error "Could not detect path to look for '%s' in" (error "Could not detect path to look for '%s' in"
filename)))) filename)))
(let ((file (if path (file (if path
`(let (file-name-handler-alist) `(expand-file-name ,filename ,path)
(expand-file-name ,filename ,path))
filename))) filename)))
`(condition-case e `(condition-case-unless-debug e
(load ,file ,noerror ,(not doom-debug-mode)) (let (file-name-handler-alist)
((debug doom-error) (signal (car e) (cdr e))) (load ,file ,noerror 'nomessage))
((debug error) (doom-error (signal (car e) (cdr e)))
(error
(let* ((source (file-name-sans-extension ,file)) (let* ((source (file-name-sans-extension ,file))
(err (cond ((file-in-directory-p source doom-core-dir) (err (cond ((not (featurep 'core))
(cons 'error (file-name-directory path)))
((file-in-directory-p source doom-core-dir)
(cons 'doom-error doom-core-dir)) (cons 'doom-error doom-core-dir))
((file-in-directory-p source doom-private-dir) ((file-in-directory-p source doom-private-dir)
(cons 'doom-private-error doom-private-dir)) (cons 'doom-private-error doom-private-dir))

View file

@ -358,58 +358,61 @@ The overall load order of Doom is as follows:
Module load order is determined by your `doom!' block. See `doom-modules-dirs' 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 for a list of all recognized module trees. Order defines precedence (from most
to least)." to least)."
(unless (keywordp (car modules)) `(let ((modules ',modules))
(setq modules (eval modules t))) (unless (keywordp (car modules))
(let ((doom-modules (setq modules (eval modules t)))
(make-hash-table :test 'equal (unless doom-modules
:size (if modules (length modules) 150) (setq doom-modules
:rehash-threshold 1.0)) (make-hash-table :test 'equal
(inhibit-message doom-inhibit-module-warnings) :size (if modules (length modules) 150)
category m) :rehash-threshold 1.0)))
(while modules (let ((inhibit-message doom-inhibit-module-warnings)
(setq m (pop modules)) obsolete category m)
(cond ((keywordp m) (setq category m)) (while modules
((not category) (error "No module category specified for %s" m)) (setq m (pop modules))
((and (listp m) (cond ((keywordp m)
(keywordp (car m))) (setq category m
(pcase (car m) obsolete (assq m doom-obsolete-modules)))
(:cond ((not category)
(cl-loop for (cond . mods) in (cdr m) (error "No module category specified for %s" m))
if (eval cond t) ((and (listp m) (keywordp (car m)))
return (prependq! modules mods))) (pcase (car m)
(:if (if (eval (cadr m) t) (:cond
(push (caddr m) modules) (cl-loop for (cond . mods) in (cdr m)
(prependq! modules (cdddr m)))) if (eval cond t)
(fn (if (or (eval (cadr m) t) return (prependq! modules mods)))
(eq fn :unless)) (:if (if (eval (cadr m) t)
(prependq! modules (cddr m)))))) (push (caddr m) modules)
((catch 'doom-modules (prependq! modules (cdddr m))))
(let* ((module (if (listp m) (car m) m)) (fn (if (or (eval (cadr m) t)
(flags (if (listp m) (cdr m)))) (eq fn :unless))
(when-let* ((obsolete (assq category doom-obsolete-modules)) (prependq! modules (cddr m))))))
(new (assq module obsolete))) ((catch 'doom-modules
(let ((newkeys (cdr new))) (let* ((module (if (listp m) (car m) m))
(if (null newkeys) (flags (if (listp m) (cdr m))))
(message "WARNING %s module was removed" key) (when-let (new (assq module obsolete))
(if (cdr newkeys) (let ((newkeys (cdr new)))
(message "WARNING %s module was removed and split into the %s modules" (if (null newkeys)
(list category module) (mapconcat #'prin1-to-string newkeys ", ")) (message "WARNING %s module was removed" key)
(message "WARNING %s module was moved to %s" (if (cdr newkeys)
(list category module) (car newkeys))) (message "WARNING %s module was removed and split into the %s modules"
(push category modules) (list category module) (mapconcat #'prin1-to-string newkeys ", "))
(dolist (key newkeys) (message "WARNING %s module was moved to %s"
(push (if flags (list category module) (car newkeys)))
(nconc (cdr key) flags) (push category modules)
(cdr key)) (dolist (key newkeys)
modules) (push (if flags
(push (car key) modules)) (nconc (cdr key) flags)
(throw 'doom-modules t)))) (cdr key))
(if-let (path (doom-module-locate-path category module)) modules)
(doom-module-set category module :flags flags :path path) (push (car key) modules))
(message "WARNING Couldn't find the %s %s module" category module))))))) (throw 'doom-modules t))))
(unless doom-interactive-mode (if-let (path (doom-module-locate-path category module))
(setq doom-inhibit-module-warnings t)) (doom-module-set category module :flags flags :path path)
`(setq doom-modules ',doom-modules))) (message "WARNING Couldn't find the %s %s module" category module)))))))
(unless doom-interactive-mode
(setq doom-inhibit-module-warnings t))
doom-modules)))
(defvar doom-disabled-packages) (defvar doom-disabled-packages)
(define-obsolete-function-alias 'def-package! 'use-package!) ; DEPRECATED (define-obsolete-function-alias 'def-package! 'use-package!) ; DEPRECATED

View file

@ -1,5 +1,12 @@
;;; core.el --- the heart of the beast -*- lexical-binding: t; -*- ;;; core.el --- the heart of the beast -*- lexical-binding: t; -*-
;; Ensure `doom-core-dir' is in `load-path'
(add-to-list 'load-path (file-name-directory load-file-name))
;;
;;; Global variables
(defconst doom-version "2.0.9" (defconst doom-version "2.0.9"
"Current version of Doom Emacs.") "Current version of Doom Emacs.")
@ -97,7 +104,7 @@ which is loaded at startup (if it exists). This is helpful if Emacs can't
\(easily) be launched from the correct shell session (particularly for MacOS \(easily) be launched from the correct shell session (particularly for MacOS
users).") users).")
(defvar doom--initial-load-path (cons doom-core-dir load-path)) (defvar doom--initial-load-path load-path)
(defvar doom--initial-process-environment process-environment) (defvar doom--initial-process-environment process-environment)
(defvar doom--initial-exec-path exec-path) (defvar doom--initial-exec-path exec-path)
(defvar doom--initial-file-name-handler-alist file-name-handler-alist) (defvar doom--initial-file-name-handler-alist file-name-handler-alist)
@ -114,9 +121,6 @@ users).")
;; ;;
;;; Emacs core configuration ;;; Emacs core configuration
;; Ensure `doom-core-dir' is in `load-path'
(push doom-core-dir load-path)
;; Reduce debug output, well, unless we've asked for it. ;; Reduce debug output, well, unless we've asked for it.
(setq debug-on-error doom-debug-mode (setq debug-on-error doom-debug-mode
jka-compr-verbose doom-debug-mode) jka-compr-verbose doom-debug-mode)
@ -159,7 +163,7 @@ users).")
;; Emacs is a huge security vulnerability, what with all the dependencies it ;; Emacs is a huge security vulnerability, what with all the dependencies it
;; pulls in from all corners of the globe. Let's at least try to be more ;; pulls in from all corners of the globe. Let's at least try to be more
;; discerning. ;; discerning.
(setq gnutls-verify-error (not (getenv "INSECURE")) (setq gnutls-verify-error t
tls-checktrust gnutls-verify-error tls-checktrust gnutls-verify-error
tls-program '("gnutls-cli --x509cafile %t -p %p %h" tls-program '("gnutls-cli --x509cafile %t -p %p %h"
;; compatibility fallbacks ;; compatibility fallbacks
@ -291,8 +295,9 @@ directory. The session files are placed by default in `doom-cache-dir'"
#'doom-try-run-hook)) #'doom-try-run-hook))
(add-hook 'hack-local-variables-hook #'doom-run-local-var-hooks-h) (add-hook 'hack-local-variables-hook #'doom-run-local-var-hooks-h)
;; If `enable-local-variables' is disabled, then `hack-local-variables-hook' is ;; If the user has disabled `enable-local-variables', then
;; never triggered. ;; `hack-local-variables-hook' is never triggered, so we trigger it at the end
;; of `after-change-major-mode-hook':
(defun doom-run-local-var-hooks-if-necessary-h () (defun doom-run-local-var-hooks-if-necessary-h ()
"Run `doom-run-local-var-hooks-h' if `enable-local-variables' is disabled." "Run `doom-run-local-var-hooks-h' if `enable-local-variables' is disabled."
(unless enable-local-variables (unless enable-local-variables
@ -418,7 +423,7 @@ in interactive sessions, nil otherwise (but logs a warning)."
(signal 'doom-autoload-error (list (file-name-nondirectory file) e)))))) (signal 'doom-autoload-error (list (file-name-nondirectory file) e))))))
(defun doom-load-envvars-file (file &optional noerror) (defun doom-load-envvars-file (file &optional noerror)
"Read and set envvars in FILE." "Read and set envvars from FILE."
(if (not (file-readable-p file)) (if (not (file-readable-p file))
(unless noerror (unless noerror
(signal 'file-error (list "Couldn't read envvar file" file))) (signal 'file-error (list "Couldn't read envvar file" file)))
@ -477,9 +482,9 @@ to least)."
;; Reset as much state as possible, so `doom-initialize' can be treated like ;; Reset as much state as possible, so `doom-initialize' can be treated like
;; a reset function. Particularly useful for reloading the config. ;; a reset function. Particularly useful for reloading the config.
(setq exec-path doom--initial-exec-path (setq-default exec-path doom--initial-exec-path
load-path doom--initial-load-path load-path doom--initial-load-path
process-environment doom--initial-process-environment) process-environment doom--initial-process-environment)
(require 'core-lib) (require 'core-lib)
(require 'core-modules) (require 'core-modules)