Refactor & reformat core.el
Backport a bit of core.el from our CLI rewrite.
This commit is contained in:
parent
b7f6532e4f
commit
b5e948054c
5 changed files with 282 additions and 279 deletions
|
@ -82,72 +82,6 @@ Accepts the same arguments as `message'."
|
|||
format-string)
|
||||
,@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-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
|
||||
(setq-local coding-system-for-read 'utf-8)
|
||||
(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-default
|
||||
process-environment
|
||||
(append (nreverse env)
|
||||
(default-value 'process-environment))
|
||||
exec-path
|
||||
(append (split-string (getenv "PATH") path-separator t)
|
||||
(list exec-directory))
|
||||
shell-file-name
|
||||
(or (getenv "SHELL")
|
||||
(default-value 'shell-file-name)))
|
||||
env)))
|
||||
|
||||
(defun doom-run-hook-on (hook-var triggers)
|
||||
"Configure HOOK-VAR to be invoked exactly once after init whenever any of the
|
||||
TRIGGERS are invoked. Once HOOK-VAR gets triggered, it resets to nil.
|
||||
|
||||
HOOK-VAR is a quoted hook.
|
||||
|
||||
TRIGGERS is a list of quoted hooks and/or sharp-quoted functions."
|
||||
(let ((fn (intern (format "%s-h" hook-var))))
|
||||
(fset
|
||||
fn (lambda (&rest _)
|
||||
(when after-init-time
|
||||
(run-hook-wrapped hook-var #'doom-try-run-hook)
|
||||
(set hook-var nil))))
|
||||
(put hook-var 'permanent-local t)
|
||||
(dolist (on triggers)
|
||||
(if (functionp on)
|
||||
(advice-add on :before fn)
|
||||
(add-hook on fn)))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Functional library
|
||||
|
||||
(defalias 'doom-partial #'apply-partially)
|
||||
|
||||
(defun doom-rpartial (fn &rest args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue