From b727d4f684a2611351189e134b64fcef3661d9f8 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 11 May 2021 09:44:04 -0500 Subject: Add `acdw/system' macro `acdw/system' eases configuration -- it returns the system when called with no arguments, acts as a test with one argument, or as a `pcase' with more than one argument. --- lisp/acdw.el | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el index a798069..a1c364d 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -21,12 +21,29 @@ ;;; Variables -(defconst acdw/system (pcase system-type - ('gnu/linux :home) - ((or 'msdos 'windows-nt) :work) - (_ :other)) +(defconst acdw/system + (pcase system-type + ('gnu/linux :home) + ((or 'msdos 'windows-nt) :work) + (_ :other)) "Which computer system is currently being used.") +(defmacro acdw/system (&rest arg) + "Convenience macro for interfacing with `acdw/system'. + +When called without arguments, it returns `acdw/system'. +When called with one argument, it returns (eq acdw/system ARG). +When called with multiple arguments, it returns `pcase' over each argument." + (cond + ((not arg) acdw/system) + ((not (cdr arg)) + `(when (eq acdw/system ,(car arg)) + ,(car arg))) + ((cdr arg) + `(pcase acdw/system + ,@arg)) + (t (error "Wrong argument type: %s" (type-of arg))))) + ;;; Utility functions ;; I don't prefix these because ... reasons. Honestly I probably should prefix @@ -162,11 +179,11 @@ if MAKE-DIRECTORY is non-nil." (defun acdw/find-emacs-source () "Find where Emacs keeps its source tree." - (pcase acdw/system - (:work (expand-file-name - (concat "~/src/emacs-" emacs-version "/src"))) - (:home (expand-file-name "~/src/pkg/emacs/src/emacs-git/src")) - (:other nil))) + (acdw/system + (:work (expand-file-name + (concat "~/src/emacs-" emacs-version "/src"))) + (:home (expand-file-name "~/src/pkg/emacs/src/emacs-git/src")) + (:other nil))) (defun acdw/gc-disable () "Functionally disable the Garbage collector." -- cgit 1.4.1-21-gabe81