From ddce674a6c389cc546502cd646625cca1b9204ec Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 7 Oct 2019 16:10:33 -0400 Subject: [PATCH] Minor refactors across the board --- bin/doom | 7 ++- core/core-lib.el | 27 ++++++----- core/core-modules.el | 107 ++++++++++++++++++++++--------------------- core/core.el | 27 ++++++----- 4 files changed, 89 insertions(+), 79 deletions(-) diff --git a/bin/doom b/bin/doom index 7a33bff35..bd381e5ab 100755 --- a/bin/doom +++ b/bin/doom @@ -10,10 +10,9 @@ ":"; exec $EMACS --script "$0" -- "$@" ":"; exit 0 -(setq user-emacs-directory - (or (getenv "EMACSDIR") - (expand-file-name "../" (file-name-directory (file-truename load-file-name))))) - +(defconst user-emacs-directory + (or (getenv "EMACSDIR") + (expand-file-name "../" (file-name-directory (file-truename load-file-name))))) (defun usage () (with-temp-buffer diff --git a/core/core-lib.el b/core/core-lib.el index 3348ab550..e139c6cd6 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -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]...)" (declare (indent 1)) (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)))) (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). If NOERROR is non-nil, don't throw an error if the file doesn't exist." - (unless path - (setq path (or (dir!) + (let* ((path (or path + (dir!) (error "Could not detect path to look for '%s' in" - filename)))) - (let ((file (if path - `(let (file-name-handler-alist) - (expand-file-name ,filename ,path)) + filename))) + (file (if path + `(expand-file-name ,filename ,path) filename))) - `(condition-case e - (load ,file ,noerror ,(not doom-debug-mode)) - ((debug doom-error) (signal (car e) (cdr e))) - ((debug error) + `(condition-case-unless-debug e + (let (file-name-handler-alist) + (load ,file ,noerror 'nomessage)) + (doom-error (signal (car e) (cdr e))) + (error (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)) ((file-in-directory-p source doom-private-dir) (cons 'doom-private-error doom-private-dir)) diff --git a/core/core-modules.el b/core/core-modules.el index d55010e61..3d9460052 100644 --- a/core/core-modules.el +++ b/core/core-modules.el @@ -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' for a list of all recognized module trees. Order defines precedence (from most to least)." - (unless (keywordp (car modules)) - (setq modules (eval modules t))) - (let ((doom-modules - (make-hash-table :test 'equal - :size (if modules (length modules) 150) - :rehash-threshold 1.0)) - (inhibit-message doom-inhibit-module-warnings) - category m) - (while modules - (setq m (pop modules)) - (cond ((keywordp m) (setq category m)) - ((not category) (error "No module category specified for %s" m)) - ((and (listp m) - (keywordp (car m))) - (pcase (car m) - (:cond - (cl-loop for (cond . mods) in (cdr m) - if (eval cond t) - return (prependq! modules mods))) - (:if (if (eval (cadr m) t) - (push (caddr m) modules) - (prependq! modules (cdddr m)))) - (fn (if (or (eval (cadr m) t) - (eq fn :unless)) - (prependq! modules (cddr m)))))) - ((catch 'doom-modules - (let* ((module (if (listp m) (car m) m)) - (flags (if (listp m) (cdr m)))) - (when-let* ((obsolete (assq category doom-obsolete-modules)) - (new (assq module obsolete))) - (let ((newkeys (cdr new))) - (if (null newkeys) - (message "WARNING %s module was removed" key) - (if (cdr newkeys) - (message "WARNING %s module was removed and split into the %s modules" - (list category module) (mapconcat #'prin1-to-string newkeys ", ")) - (message "WARNING %s module was moved to %s" - (list category module) (car newkeys))) - (push category modules) - (dolist (key newkeys) - (push (if flags - (nconc (cdr key) flags) - (cdr key)) - modules) - (push (car key) modules)) - (throw 'doom-modules t)))) - (if-let (path (doom-module-locate-path category module)) - (doom-module-set category module :flags flags :path path) - (message "WARNING Couldn't find the %s %s module" category module))))))) - (unless doom-interactive-mode - (setq doom-inhibit-module-warnings t)) - `(setq doom-modules ',doom-modules))) + `(let ((modules ',modules)) + (unless (keywordp (car modules)) + (setq modules (eval modules t))) + (unless doom-modules + (setq doom-modules + (make-hash-table :test 'equal + :size (if modules (length modules) 150) + :rehash-threshold 1.0))) + (let ((inhibit-message doom-inhibit-module-warnings) + obsolete category m) + (while modules + (setq m (pop modules)) + (cond ((keywordp m) + (setq category m + obsolete (assq m doom-obsolete-modules))) + ((not category) + (error "No module category specified for %s" m)) + ((and (listp m) (keywordp (car m))) + (pcase (car m) + (:cond + (cl-loop for (cond . mods) in (cdr m) + if (eval cond t) + return (prependq! modules mods))) + (:if (if (eval (cadr m) t) + (push (caddr m) modules) + (prependq! modules (cdddr m)))) + (fn (if (or (eval (cadr m) t) + (eq fn :unless)) + (prependq! modules (cddr m)))))) + ((catch 'doom-modules + (let* ((module (if (listp m) (car m) m)) + (flags (if (listp m) (cdr m)))) + (when-let (new (assq module obsolete)) + (let ((newkeys (cdr new))) + (if (null newkeys) + (message "WARNING %s module was removed" key) + (if (cdr newkeys) + (message "WARNING %s module was removed and split into the %s modules" + (list category module) (mapconcat #'prin1-to-string newkeys ", ")) + (message "WARNING %s module was moved to %s" + (list category module) (car newkeys))) + (push category modules) + (dolist (key newkeys) + (push (if flags + (nconc (cdr key) flags) + (cdr key)) + modules) + (push (car key) modules)) + (throw 'doom-modules t)))) + (if-let (path (doom-module-locate-path category module)) + (doom-module-set category module :flags flags :path path) + (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) (define-obsolete-function-alias 'def-package! 'use-package!) ; DEPRECATED diff --git a/core/core.el b/core/core.el index 896210325..8cd6dccfc 100644 --- a/core/core.el +++ b/core/core.el @@ -1,5 +1,12 @@ ;;; 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" "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 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-exec-path exec-path) (defvar doom--initial-file-name-handler-alist file-name-handler-alist) @@ -114,9 +121,6 @@ users).") ;; ;;; 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. (setq debug-on-error 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 ;; pulls in from all corners of the globe. Let's at least try to be more ;; discerning. -(setq gnutls-verify-error (not (getenv "INSECURE")) +(setq gnutls-verify-error t tls-checktrust gnutls-verify-error tls-program '("gnutls-cli --x509cafile %t -p %p %h" ;; compatibility fallbacks @@ -291,8 +295,9 @@ directory. The session files are placed by default in `doom-cache-dir'" #'doom-try-run-hook)) (add-hook 'hack-local-variables-hook #'doom-run-local-var-hooks-h) -;; If `enable-local-variables' is disabled, then `hack-local-variables-hook' is -;; never triggered. +;; If the user has disabled `enable-local-variables', then +;; `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 () "Run `doom-run-local-var-hooks-h' if `enable-local-variables' is disabled." (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)))))) (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)) (unless noerror (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 ;; a reset function. Particularly useful for reloading the config. - (setq exec-path doom--initial-exec-path - load-path doom--initial-load-path - process-environment doom--initial-process-environment) + (setq-default exec-path doom--initial-exec-path + load-path doom--initial-load-path + process-environment doom--initial-process-environment) (require 'core-lib) (require 'core-modules)