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,11 +10,10 @@
":"; 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
(insert (format! "%s %s [COMMAND] [ARGS...]\n" (insert (format! "%s %s [COMMAND] [ARGS...]\n"

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))))
(let ((file (if path
`(let (file-name-handler-alist)
(expand-file-name ,filename ,path))
filename))) filename)))
`(condition-case e (file (if path
(load ,file ,noerror ,(not doom-debug-mode)) `(expand-file-name ,filename ,path)
((debug doom-error) (signal (car e) (cdr e))) filename)))
((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)) (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,20 +358,24 @@ 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)."
`(let ((modules ',modules))
(unless (keywordp (car modules)) (unless (keywordp (car modules))
(setq modules (eval modules t))) (setq modules (eval modules t)))
(let ((doom-modules (unless doom-modules
(setq doom-modules
(make-hash-table :test 'equal (make-hash-table :test 'equal
:size (if modules (length modules) 150) :size (if modules (length modules) 150)
:rehash-threshold 1.0)) :rehash-threshold 1.0)))
(inhibit-message doom-inhibit-module-warnings) (let ((inhibit-message doom-inhibit-module-warnings)
category m) obsolete category m)
(while modules (while modules
(setq m (pop modules)) (setq m (pop modules))
(cond ((keywordp m) (setq category m)) (cond ((keywordp m)
((not category) (error "No module category specified for %s" m)) (setq category m
((and (listp m) obsolete (assq m doom-obsolete-modules)))
(keywordp (car m))) ((not category)
(error "No module category specified for %s" m))
((and (listp m) (keywordp (car m)))
(pcase (car m) (pcase (car m)
(:cond (:cond
(cl-loop for (cond . mods) in (cdr m) (cl-loop for (cond . mods) in (cdr m)
@ -386,8 +390,7 @@ to least)."
((catch 'doom-modules ((catch 'doom-modules
(let* ((module (if (listp m) (car m) m)) (let* ((module (if (listp m) (car m) m))
(flags (if (listp m) (cdr m)))) (flags (if (listp m) (cdr m))))
(when-let* ((obsolete (assq category doom-obsolete-modules)) (when-let (new (assq module obsolete))
(new (assq module obsolete)))
(let ((newkeys (cdr new))) (let ((newkeys (cdr new)))
(if (null newkeys) (if (null newkeys)
(message "WARNING %s module was removed" key) (message "WARNING %s module was removed" key)
@ -409,7 +412,7 @@ to least)."
(message "WARNING Couldn't find the %s %s module" category module))))))) (message "WARNING Couldn't find the %s %s module" category module)))))))
(unless doom-interactive-mode (unless doom-interactive-mode
(setq doom-inhibit-module-warnings t)) (setq doom-inhibit-module-warnings t))
`(setq doom-modules ',doom-modules))) 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,7 +482,7 @@ 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)