Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to load a user config file #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lisp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,36 @@
(new-view handle-new-view-event)
(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)))))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting of the above code is a little difficult to read in the website; specifically, the two progn blocks should be indented to line up under the test config-file.


(defun run-server ()
(disable-fpu-exceptions)
(hrt:load-foreign-libraries)
(log-init :level :trace)
(sb-ext:enable-debugger)
(load-config-file)
(cffi:with-foreign-objects ((output-callbacks '(:struct hrt-output-callbacks))
(seat-callbacks '(:struct hrt-seat-callbacks))
(view-callbacks '(:struct hrt-view-callbacks))
Expand Down