From 7a1ff0c1bcc76a5eaed2c3bc4ad613bb74f9ee74 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 4 Jan 2022 21:09:53 -0600 Subject: Add a function and variable system-system --- lisp/system.el | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'lisp/system.el') diff --git a/lisp/system.el b/lisp/system.el index f2e85a1..7fe39f1 100644 --- a/lisp/system.el +++ b/lisp/system.el @@ -58,9 +58,13 @@ A floating-point number is recommended, since that makes it relative to the `default' face height." :type 'number) +(defvar system-system nil + "The current system's symbol. +Do not edit this by hand. Instead, call `system-get-system'.") + (defvar system-file nil "The current system's file for system-specific configuration. -Do not edit this by hand. Instead, call `system-system-file'.") +Do not edit this by hand. Instead, call `system-get-system-file'.") ;;; Functions @@ -78,10 +82,17 @@ Do not edit this by hand. Instead, call `system-system-file'.") This function is like `warn', except it uses the `system' type." (display-warning 'system (apply #'format-message message args))) -(defun system-system-file (&optional system refresh-cache set-system-file-p) +(defun system-get-system () + "Determine the current system." + (cl-loop for (p . s) in system-load-alist + if (with-demoted-errors (format "Problem running function `%s'" p) + (funcall p)) + return (setq system-system s))) + +(defun system-get-system-file (&optional system refresh-cache set-system-file-p) "Determine the current system's system-specific file. -The current system's file will be returned, and the value of -`system-file' set /unless/ the parameter SYSTEM was passed to +The current system's file will be returned. The value of +`system-file' is set, /unless/ the parameter SYSTEM was passed to this function and SET-SYSTEM-FILE-P is nil. If both SYSTEM and SET-SYSTEM-FILE-P are non-nil, this function will still set `system-file'. @@ -97,8 +108,7 @@ This function will only look for system-specific files in `system-load-directory'." (let* ((system* (or system (and system-file (not refresh-cache)) - (cl-loop for (p . s) in system-load-alist - if (funcall p) return s))) + (system-get-system))) (file (expand-file-name (format "%s" system*) system-load-directory))) (when (or (not system) (and system set-system-file-p)) @@ -109,7 +119,7 @@ This function will only look for system-specific files in (defun system-settings-load (&optional system error nomessage) "Load system settings. Load settings from `system-file', or the `system-file' as -determined by SYSTEM, if passed. See `system-system-file' for +determined by SYSTEM, if passed. See `system-get-system-file' for details on how the `system-file' is determined. ERROR determines how to deal with errors: if nil, warn the user @@ -118,7 +128,7 @@ can't be determined. If t, those are elevated to errors. If any other value, the errors are completely ignored. NOMESSAGE is passed directly to `load'." - (let ((file (system-system-file system))) + (let ((file (system-get-system-file system))) (if file (condition-case e (load file nil nomessage) @@ -137,10 +147,8 @@ NOMESSAGE is passed directly to `load'." (mapcar (lambda (a) (format "%s" (cdr a))) system-load-alist) nil t nil nil - (cl-loop for (p . s) in system-load-alist - if (funcall p) - return (format "%s" s))))) - (find-file (cl-loop with file = (system-system-file system) + (format "%s" (system-get-system))))) + (find-file (cl-loop with file = (system-get-system-file system) for cand in (list file (concat file ".el")) if (file-exists-p cand) -- cgit 1.4.1-21-gabe81