Move core helpers to core-lib
Since they can be generally useful.
This commit is contained in:
parent
f61fa50336
commit
1442e694fb
2 changed files with 53 additions and 46 deletions
|
@ -85,6 +85,58 @@ Accepts the same arguments as `message'."
|
||||||
format-string)
|
format-string)
|
||||||
,@args))))
|
,@args))))
|
||||||
|
|
||||||
|
(defun doom-try-run-hook (hook)
|
||||||
|
"Run HOOK (a hook function) with better error handling.
|
||||||
|
Meant to be used with `run-hook-wrapped'."
|
||||||
|
(doom-log "Running doom hook: %s" hook)
|
||||||
|
(condition-case e
|
||||||
|
(funcall hook)
|
||||||
|
((debug error)
|
||||||
|
(signal 'doom-hook-error (list hook e))))
|
||||||
|
;; return nil so `run-hook-wrapped' won't short circuit
|
||||||
|
nil)
|
||||||
|
|
||||||
|
(defun doom-load-autoloads-file (file &optional noerror)
|
||||||
|
"Tries to load FILE (an autoloads file).
|
||||||
|
Return t on success, nil otherwise (but logs a warning)."
|
||||||
|
(condition-case e
|
||||||
|
;; Avoid `file-name-sans-extension' for premature optimization reasons.
|
||||||
|
;; `string-remove-suffix' is much cheaper (because it does no file sanity
|
||||||
|
;; checks during or after; just plain ol' string manipulation).
|
||||||
|
(load (string-remove-suffix ".el" file) noerror 'nomessage)
|
||||||
|
((debug error)
|
||||||
|
(message "Autoload file error: %s -> %s" (file-name-nondirectory file) e)
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
(defun doom-load-envvars-file (file &optional noerror)
|
||||||
|
"Read and set envvars from FILE.
|
||||||
|
If NOERROR is non-nil, don't throw an error if the file doesn't exist or is
|
||||||
|
unreadable. Returns the names of envvars that were changed."
|
||||||
|
(if (null (file-exists-p file))
|
||||||
|
(unless noerror
|
||||||
|
(signal 'file-error (list "No envvar file exists" file)))
|
||||||
|
(when-let
|
||||||
|
(env
|
||||||
|
(with-temp-buffer
|
||||||
|
(save-excursion
|
||||||
|
(insert "\0\n") ; to prevent off-by-one
|
||||||
|
(insert-file-contents file))
|
||||||
|
(save-match-data
|
||||||
|
(when (re-search-forward "\0\n *\\([^#= \n]*\\)=" nil t)
|
||||||
|
(setq
|
||||||
|
env (split-string (buffer-substring (match-beginning 1) (point-max))
|
||||||
|
"\0\n"
|
||||||
|
'omit-nulls))))))
|
||||||
|
(setq process-environment (append (nreverse env) process-environment)
|
||||||
|
exec-path (append (split-string (getenv "PATH") path-separator t)
|
||||||
|
(list exec-directory))
|
||||||
|
shell-file-name (or (getenv "SHELL") shell-file-name))
|
||||||
|
env)))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;;; Functional library
|
||||||
|
|
||||||
(defalias 'doom-partial #'apply-partially)
|
(defalias 'doom-partial #'apply-partially)
|
||||||
|
|
||||||
(defun doom-rpartial (fn &rest args)
|
(defun doom-rpartial (fn &rest args)
|
||||||
|
|
47
core/core.el
47
core/core.el
|
@ -427,17 +427,6 @@ If this is a daemon session, load them all immediately instead."
|
||||||
;;
|
;;
|
||||||
;;; Bootstrap helpers
|
;;; Bootstrap helpers
|
||||||
|
|
||||||
(defun doom-try-run-hook (hook)
|
|
||||||
"Run HOOK (a hook function) with better error handling.
|
|
||||||
Meant to be used with `run-hook-wrapped'."
|
|
||||||
(doom-log "Running doom hook: %s" hook)
|
|
||||||
(condition-case e
|
|
||||||
(funcall hook)
|
|
||||||
((debug error)
|
|
||||||
(signal 'doom-hook-error (list hook e))))
|
|
||||||
;; return nil so `run-hook-wrapped' won't short circuit
|
|
||||||
nil)
|
|
||||||
|
|
||||||
(defun doom-display-benchmark-h (&optional return-p)
|
(defun doom-display-benchmark-h (&optional return-p)
|
||||||
"Display a benchmark including number of packages and modules loaded.
|
"Display a benchmark including number of packages and modules loaded.
|
||||||
|
|
||||||
|
@ -450,40 +439,6 @@ If RETURN-P, return the message as a string instead of displaying it."
|
||||||
(setq doom-init-time
|
(setq doom-init-time
|
||||||
(float-time (time-subtract (current-time) before-init-time))))))
|
(float-time (time-subtract (current-time) before-init-time))))))
|
||||||
|
|
||||||
(defun doom-load-autoloads-file (file &optional noerror)
|
|
||||||
"Tries to load FILE (an autoloads file).
|
|
||||||
Return t on success, nil otherwise (but logs a warning)."
|
|
||||||
(condition-case e
|
|
||||||
(load (substring file 0 -3) noerror 'nomessage)
|
|
||||||
((debug error)
|
|
||||||
(message "Autoload file error: %s -> %s" (file-name-nondirectory file) e)
|
|
||||||
nil)))
|
|
||||||
|
|
||||||
(defun doom-load-envvars-file (file &optional noerror)
|
|
||||||
"Read and set envvars from FILE.
|
|
||||||
If NOERROR is non-nil, don't throw an error if the file doesn't exist or is
|
|
||||||
unreadable. Returns the names of envvars that were changed."
|
|
||||||
(if (not (file-readable-p file))
|
|
||||||
(unless noerror
|
|
||||||
(signal 'file-error (list "No envvar file exists" file)))
|
|
||||||
(when-let
|
|
||||||
(env
|
|
||||||
(with-temp-buffer
|
|
||||||
(save-excursion
|
|
||||||
(insert "\0\n") ; to prevent off-by-one
|
|
||||||
(insert-file-contents file))
|
|
||||||
(save-match-data
|
|
||||||
(when (re-search-forward "\0\n *\\([^#= \n]*\\)=" nil t)
|
|
||||||
(setq
|
|
||||||
env (split-string (buffer-substring (match-beginning 1) (point-max))
|
|
||||||
"\0\n"
|
|
||||||
'omit-nulls))))))
|
|
||||||
(setq process-environment (append (nreverse env) process-environment)
|
|
||||||
exec-path (append (split-string (getenv "PATH") path-separator t)
|
|
||||||
(list exec-directory))
|
|
||||||
shell-file-name (or (getenv "SHELL") shell-file-name))
|
|
||||||
env)))
|
|
||||||
|
|
||||||
(defun doom-initialize (&optional force-p noerror)
|
(defun doom-initialize (&optional force-p noerror)
|
||||||
"Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil).
|
"Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil).
|
||||||
|
|
||||||
|
@ -502,7 +457,7 @@ The overall load order of Doom is as follows:
|
||||||
Module config.el files
|
Module config.el files
|
||||||
~/.doom.d/config.el
|
~/.doom.d/config.el
|
||||||
`doom-init-modules-hook'
|
`doom-init-modules-hook'
|
||||||
`doom-after-init-hook' (`after-init-hook')
|
`doom-after-init-modules-hook' (`after-init-hook')
|
||||||
`emacs-startup-hook'
|
`emacs-startup-hook'
|
||||||
`doom-init-ui-hook'
|
`doom-init-ui-hook'
|
||||||
`window-setup-hook'
|
`window-setup-hook'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue