From 2aad2b894bfcc1e34f3bbfd01e4a1ea1288f3fc1 Mon Sep 17 00:00:00 2001 From: Thomas Atkinson Date: Tue, 16 Jan 2024 11:02:16 +1100 Subject: [PATCH 1/2] Add function to load a user config file This loads a config file first checking $XDG_CONFIG_HOME and if that does not exist falls back to .config/mahogany/init.lisp. It is adapted from the function in stumpwm. --- lisp/main.lisp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lisp/main.lisp b/lisp/main.lisp index 5d47937..fc54c51 100644 --- a/lisp/main.lisp +++ b/lisp/main.lisp @@ -26,11 +26,36 @@ (hrt:new-view handle-new-view-event) (hrt:view-destroyed handle-view-destroyed-event))) +(defun load-config-file (&optional (catch-errors t)) + "Load the user's config file. Returns a values list: whether the file loaded (t if no +rc files exist), the error if it didn't, and the config file that was +loaded. When CATCH-ERRORS is nil, errors are left to be handled +further up. " + (let* ((xdg-config + (probe-file (merge-pathnames #p"mahogany/init.lisp" (uiop:xdg-config-home)))) + (fallback-config + (probe-file (merge-pathnames #p".config/mahogany/init.lisp" (user-homedir-pathname)))) + (config-file (or xdg-config fallback-config))) + (if config-file + (progn + (log-string :debug "Found config file at ~a" config-file) + (if catch-errors + (handler-case (load config-file) + (error (c) (values nil (format nil "~a" c) config-file)) + (:no-error (&rest args) (declare (ignore args)) (values t nil config-file))) + (progn + (load config-file) + (values t nil config-file)))) + (progn + (log-string :debug "Did not find config file") + (values t nil nil))))) + (defun run-server () (disable-fpu-exceptions) (hrt:load-foreign-libraries) (log-init :level :trace) (enable-debugger) + (load-config-file) (cffi:with-foreign-objects ((output-callbacks '(:struct hrt:hrt-output-callbacks)) (seat-callbacks '(:struct hrt:hrt-seat-callbacks)) (view-callbacks '(:struct hrt:hrt-view-callbacks)) From 2af400bf1dac27f19103b64a4f2642dba344ff60 Mon Sep 17 00:00:00 2001 From: Stuart Dilts Date: Sun, 19 Jan 2025 08:42:31 -0700 Subject: [PATCH 2/2] Don't catch errors by default when loading config file Since most errors are going to be unrecoverable at this point, don't supress them. --- lisp/main.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/main.lisp b/lisp/main.lisp index fc54c51..2855ef8 100644 --- a/lisp/main.lisp +++ b/lisp/main.lisp @@ -26,7 +26,7 @@ (hrt:new-view handle-new-view-event) (hrt:view-destroyed handle-view-destroyed-event))) -(defun load-config-file (&optional (catch-errors t)) +(defun load-config-file (&optional (catch-errors nil)) "Load the user's config file. Returns a values list: whether the file loaded (t if no rc files exist), the error if it didn't, and the config file that was loaded. When CATCH-ERRORS is nil, errors are left to be handled