refactor(lib): provide doom-libs as subfeatures

This allows us to load them via doom-require. Why not use normal
features? Because Doom's libraries are designed to be loaded as part of
Doom, and will openly rely on Doom state if needed; this is a contract I
want to enforce by ensuring their only entry points are through
`doom-require` or autoloading.

I will add them to the rest of the libraries later.

Site-node: this also adds Commentary+Code to the comment headings, as I
want a space to use that space to describe the library, when I get
around to it.
This commit is contained in:
Henrik Lissner 2022-09-08 00:08:54 +02:00
parent a179b8d262
commit b121c5e1c6
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
8 changed files with 57 additions and 20 deletions

View file

@ -65,21 +65,23 @@
;; Load just the... bear necessities~
(require 'seq)
(require 'map)
;; Load these eagerly, since autoloads may not have been generated/loaded yet
(load! "lib/process")
(load! "lib/system")
(load! "lib/git")
(load! "lib/plist")
(load! "lib/files")
(load! "lib/debug")
(load! "lib/print")
;; (load! "lib/autoloads")
;; Use our own home-grown debugger so we can capture backtraces, make them more
;; presentable, and write them to a file. Cleaner backtraces are better UX than
;; the giant wall of text the default debugger throws up.
;; Use our own home-grown debugger so we can capture backtraces, make them
;; more presentable, and write them to a file. Cleaner backtraces are better
;; UX than the giant wall of text the default debugger throws up.
(doom-require 'doom-lib 'debug)
(setq debugger #'doom-debugger)
;; Then load the rest of Doom's libs eagerly, since autoloads may not be
;; generated/loaded yet.
(doom-require 'doom-lib 'process)
(doom-require 'doom-lib 'system)
(doom-require 'doom-lib 'git)
(doom-require 'doom-lib 'plist)
(doom-require 'doom-lib 'files)
(doom-require 'doom-lib 'print)
;; (doom-require 'doom-lib 'autoloads)
;; Ensure straight and core packages are ready to go for CLI commands.
;; (require 'doom-profiles)
(require 'doom-modules)

View file

@ -1,4 +1,6 @@
;;; lisp/lib/debug.el -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
;;
;;; Doom's debug mode
@ -414,3 +416,6 @@ copies it to your clipboard, ready to be pasted into bug reports!"
(profiler-report)
(profiler-stop))
(setq doom--profiler (not doom--profiler)))
(provide 'doom-lib '(debug))
;;; debug.el ends here

View file

@ -1,4 +1,6 @@
;;; lisp/lib/files.el -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(defun doom-files--build-checks (spec &optional directory)
"Converts a simple nested series of or/and forms into a series of
@ -507,3 +509,6 @@ If FORCE-P, overwrite the destination file if it exists, without confirmation."
(setq recentf-list (delete file recentf-list))
(recentf-save-list)
(message "Removed %S from `recentf-list'" (abbreviate-file-name file)))
(provide 'doom-lib '(files))
;;; files.el ends here

View file

@ -1,4 +1,6 @@
;;; lisp/lib/git.el -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
;;;###autoload
(defun doom-git-toplevel (&rest segments)
@ -9,3 +11,6 @@
(apply #'file-name-concat output segments)
;; TODO throw stderr as error
(user-error "Not in a git repo: %s" default-directory))))
(provide 'doom-lib '(git))
;;; git.el ends here

View file

@ -1,4 +1,6 @@
;;; lisp/lib/plist.el -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
;;
;;; Macros
@ -59,3 +61,6 @@
(push (cadr plist) keys)
(setq plist (cddr plist)))
keys))
(provide 'doom-lib '(plist))
;;; plist.el ends here

View file

@ -1,16 +1,20 @@
;;; lisp/lib/print.el -*- lexical-binding: t; -*-
;;; Commentary
;;;
;;; This is Doom's output library, for controlling what does and doesn't get
;;; logged, and provides a simple DSL for formatting output. It's mainly to
;;; serve the noninteractive use-case, as `message' is more than good enough in
;;; interactive sessions, but `print!' and `doom-log' are safe to use as a
;;; drop-in replacement.
;;;
;;
;; This is Doom's output library, for controlling what does and doesn't get
;; logged, and provides a simple DSL for formatting output. It's mainly to
;; serve the noninteractive use-case, as `message' is more than good enough in
;; interactive sessions, but `print!' and `doom-log' are safe to use as a
;; drop-in replacement.
;;
;;; Code:
(eval-when-compile (require 'doom)) ; be silent, o'byte-compiler
(require 'ansi-color)
;;
;;; Variables
(defvar doom-print-ansi-alist
'(;; fx
(bold 1 :weight bold)
@ -438,3 +442,6 @@ transformative logic."
(doom-print--apply (cdr forms) t)
nil))
(forms)))
(provide 'doom-lib '(print))
;;; print.el ends here

View file

@ -1,4 +1,6 @@
;;; lisp/lib/process.el -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
;;;###autoload
(defun doom-call-process (command &rest args)
@ -40,3 +42,6 @@ Warning: freezes indefinitely on any stdin prompt."
(sit-for 0.1))
(process-exit-status process))
(string-trim (buffer-string)))))
(provide 'doom-lib '(process))
;;; process.el ends here

View file

@ -106,3 +106,6 @@ Tries to be portable. Returns 1 if cannot be determined."
(user-error "Failed to look up number of processors, because:\n\n%s"
(cdr cpus)))))
1)))))
(provide 'doom-lib '(system))
;;; system.el ends here