From ef74ca5c9b7445816a5d57f3357c769ff30b62f7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 4 Jan 2022 15:29:54 -0600 Subject: [PATCH] Add system-file, system-system-file, and change logic around --- early-init.el | 2 ++ lisp/system.el | 84 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/early-init.el b/early-init.el index 1917779..17b3844 100644 --- a/early-init.el +++ b/early-init.el @@ -54,6 +54,8 @@ See `no-littering' for examples.") ;; Load system-specific changes. (progn (require 'system) + (setq system-default-font "DejaVu Sans Mono" + system-variable-pitch-font "DejaVu Sans") (setq system-load-directory (sync/ "emacs/systems/" t)) (system-settings-load nil :nowarn)) diff --git a/lisp/system.el b/lisp/system.el index 9bb057c..f2e85a1 100644 --- a/lisp/system.el +++ b/lisp/system.el @@ -58,6 +58,10 @@ A floating-point number is recommended, since that makes it relative to the `default' face height." :type 'number) +(defvar system-file nil + "The current system's file for system-specific configuration. +Do not edit this by hand. Instead, call `system-system-file'.") + ;;; Functions ;; Convenience functions for systems @@ -74,40 +78,74 @@ relative to the `default' face height." 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) + "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 +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'. + +If SYSTEM is not passed, and `system-file' is set, simply return +its value /unless/ REFRESH-CACHE is non-nil, in which case +`system-load-alist' will be looped through to find the +appropriate system by testing the car of each cell there. When +one matches, use the cdr of that cell as SYSTEM. If none +matches, return nil. + +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))) + (file (expand-file-name (format "%s" system*) system-load-directory))) + (when (or (not system) + (and system set-system-file-p)) + (setq system-file file)) + file)) + ;;;###autoload (defun system-settings-load (&optional system error nomessage) "Load system settings. -If optional SYSTEM (a symbol or a string) is not provided, loop -through `system-load-alist', testing the car of each cell there. -When one matches, use the cdr of that cell as SYSTEM. Either -way, look in `system-load-directory' for the files to load. +Load settings from `system-file', or the `system-file' as +determined by SYSTEM, if passed. See `system-system-file' for +details on how the `system-file' is determined. -If none match, warn the user. +ERROR determines how to deal with errors: if nil, warn the user +when `system-file' can't be found or when the system being used +can't be determined. If t, those are elevated to errors. If any +other value, the errors are completely ignored. -Optional argument ERROR is similar to in `load', but negated: if -t, it will generate an error; if nil, it will warn the user; -otherwise, if ERROR is anything else, it will be completely -silent. - -NOMESSAGE is passed as-is to `load'." - (let ((system (or system - (cl-loop for (p . s) in system-load-alist - if (funcall p) - return s)))) - (if system +NOMESSAGE is passed directly to `load'." + (let ((file (system-system-file system))) + (if file (condition-case e - (load (expand-file-name (format "%s" system) system-load-directory) - nil nomessage) + (load file nil nomessage) (t (cond ((eq error t) (signal (car e) (cdr e))) - ((null error) (system-warn - (concat - "Couldn't find file `%s' to load" - " (Looked in %s).") - system system-load-directory))))) + ((null error) (system-warn "Couldn't find file `%s'." + file))))) (funcall (cond ((eq error t) #'error) ((null error) #'system-warn) (t #'ignore)) "Could not determine the system being used.")))) +;;;###autoload +(defun system-find-system-file (&optional system) + "Find the current system's system-file." + (interactive (list (completing-read "System file: " + (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) + for cand in (list file + (concat file ".el")) + if (file-exists-p cand) + return cand + finally return cand))) + (provide 'system) ;;; system.el ends here