Add system-file, system-system-file, and change logic around
This commit is contained in:
parent
7c76d024bf
commit
ef74ca5c9b
|
@ -54,6 +54,8 @@ See `no-littering' for examples.")
|
||||||
|
|
||||||
;; Load system-specific changes.
|
;; Load system-specific changes.
|
||||||
(progn (require 'system)
|
(progn (require 'system)
|
||||||
|
(setq system-default-font "DejaVu Sans Mono"
|
||||||
|
system-variable-pitch-font "DejaVu Sans")
|
||||||
(setq system-load-directory (sync/ "emacs/systems/" t))
|
(setq system-load-directory (sync/ "emacs/systems/" t))
|
||||||
(system-settings-load nil :nowarn))
|
(system-settings-load nil :nowarn))
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,10 @@ A floating-point number is recommended, since that makes it
|
||||||
relative to the `default' face height."
|
relative to the `default' face height."
|
||||||
:type 'number)
|
: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
|
;;; Functions
|
||||||
|
|
||||||
;; Convenience functions for systems
|
;; 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."
|
This function is like `warn', except it uses the `system' type."
|
||||||
(display-warning 'system (apply #'format-message message args)))
|
(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
|
;;;###autoload
|
||||||
(defun system-settings-load (&optional system error nomessage)
|
(defun system-settings-load (&optional system error nomessage)
|
||||||
"Load system settings.
|
"Load system settings.
|
||||||
If optional SYSTEM (a symbol or a string) is not provided, loop
|
Load settings from `system-file', or the `system-file' as
|
||||||
through `system-load-alist', testing the car of each cell there.
|
determined by SYSTEM, if passed. See `system-system-file' for
|
||||||
When one matches, use the cdr of that cell as SYSTEM. Either
|
details on how the `system-file' is determined.
|
||||||
way, look in `system-load-directory' for the files to load.
|
|
||||||
|
|
||||||
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
|
NOMESSAGE is passed directly to `load'."
|
||||||
t, it will generate an error; if nil, it will warn the user;
|
(let ((file (system-system-file system)))
|
||||||
otherwise, if ERROR is anything else, it will be completely
|
(if file
|
||||||
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
|
|
||||||
(condition-case e
|
(condition-case e
|
||||||
(load (expand-file-name (format "%s" system) system-load-directory)
|
(load file nil nomessage)
|
||||||
nil nomessage)
|
|
||||||
(t (cond ((eq error t) (signal (car e) (cdr e)))
|
(t (cond ((eq error t) (signal (car e) (cdr e)))
|
||||||
((null error) (system-warn
|
((null error) (system-warn "Couldn't find file `%s'."
|
||||||
(concat
|
file)))))
|
||||||
"Couldn't find file `%s' to load"
|
|
||||||
" (Looked in %s).")
|
|
||||||
system system-load-directory)))))
|
|
||||||
(funcall (cond ((eq error t) #'error)
|
(funcall (cond ((eq error t) #'error)
|
||||||
((null error) #'system-warn)
|
((null error) #'system-warn)
|
||||||
(t #'ignore))
|
(t #'ignore))
|
||||||
"Could not determine the system being used."))))
|
"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)
|
(provide 'system)
|
||||||
;;; system.el ends here
|
;;; system.el ends here
|
||||||
|
|
Loading…
Reference in New Issue