-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Settings backend #3120
Settings backend #3120
Conversation
nyxt.asd
Outdated
@@ -220,6 +220,7 @@ The renderer is configured from NYXT_RENDERER or `*nyxt-renderer*'.")) | |||
:depends-on ("Core modes" "Modes") | |||
:components | |||
((:file "help") | |||
(:file "setting") ; REVIEW: Move to other module? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when you say module, are you using the Python notation to mean file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @hgluka meant package here. Then there's the fact that a single package is usually used in a .lisp
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comment was left by @Ambrevar, but I assume he was talking about whether the setting
file fits into the "Help" module along with help
, manual
, changelog
, etc.
That comment was left by Ambrevar, but I assume he was talking about whether the `setting` file fits into the "Help" module along with `help`, `manual`, `changelog`, etc.
Right! That's an ASDF module Pierre must've meant.
|
source/user-classes.lisp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I was trying to solve here is that auto-configure
uses customize-instance
,
while extend-configuration
uses customize-hook
. This means that when you apply a setting
with :auto-config-p t
and then restart Nyxt, applying another setting to that slot will have no effect on new instances.
Still, this seems to me like a very big change that could have unforeseen consequences.
What do you think? @Ambrevar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hgluka just a general piece of advice: write tests with regards to the customization facilities to capture all of the invariants. I can help you with some details if you get stuck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that when you apply a setting
with :auto-config-p t and then restart Nyxt, applying another setting to that slot will have no effect on new instances.
Still, this seems to me like a very big change that could have unforeseen consequences.
What do you think? @Ambrevar
I'm late to the party, but the change would only make the behavior more predictable and compatible with other define-configuration
settings. Especially after #3163.
It's more confusing when one configures Nyxt via Common Settings, then adds some setting via define-configuration
in config.lisp
only to see that it's not applied whatever value they pick. So using customize-hook
is a bugfix, not a breaking change.
The issue I was trying to solve here is that `auto-configure` uses `customize-instance`,
while `extend-configuration` uses `customize-hook`. This means that when you apply a setting
with `:auto-config-p t` and then restart Nyxt, applying another setting to that slot will have no effect on new instances.
That's a perfect analysis of the issue. We should've moved to customize-hook (and/or define-configuration) a long time ago.
I'm pretty sure it'll make things simpler and more predictable, with only a couple of cornercases (that are present in define-configuration anyway) staying broken.
(These corner-cases are mainly the handler order and redefinition problems: if you redefine the buffer keyscheme to be Emacs, then VI, then back to Emacs—all in one file—then it might end up with either Emacs or VI. That's because customize-hook handler order is not guaranteed (but it should be pretty intuitive in most cases.) Anyway, this handler order problem happens regardless of customize-instance/customize-hook dichotomy, so let's ignoreit for now.)
|
ed6c019
to
aa3aa23
Compare
The concept of "settings" needs to be formalized. This is what we do here. It's similar to nhooks handlers and it's applied with the `apply-setting' generic function.
Add `find-writer` function which looks for a slot writer in the target class or any of its superclasses.
Add `apply-slot-setting` function as a (bare-bones, first-iteration) front-end for the setting package.
Fix `find-writer` so that it finds the writer even when it's defined with `defmethod` outside of the class definition.
aa3aa23
to
50196b9
Compare
Hey, I've been working on this for about a month and I'm kind of getting stuck, so (as @jmercouris advised) I wanted to update everyone/ask for feedback and then maybe take a break from this PR and do something else before coming back to it. The good part is that the There are two big issues I haven't solved:
If anyone has ideas for solving those two issues, let me know! |
That's a huge progress!
So rewriting it with hooks solves the problem? I'm not sure I get what the thing is about, can you expand on it?
This problem is equivalent to "list all the instances of all classes" problem. Which, as far as I digged into the problem (I did, for quite some time) is hard and non-portable. SBCL has We can hack up around this problem by keeping count on all the This approach would be somewhat similar to what |
No, sorry for the confusion, those two things are only related because they have to do with (defmethod customize-instance ((browser browser) &key)
(setf (slot-value browser 'default-new-buffer-url) "https://example.com")) That's good, everything works. (defmethod customize-instance ((browser browser) &key)
(setf (slot-value browser 'theme) #<theme:theme {1008530413}>)) We need the object there to be serialized, so that the file can be loaded on startup. |
I see now! A crude solution that I can come up with is comparing which slots in the (make-instance 'theme:theme :background-color "black" :on-background-color "white") That's an incomplete solution, because current slot values for objects might be a result of some complex computation based on absolutely different initargs, but, I guess, that's the problem of the class with such complex computations 😄 I have a vague recollection of something like this instance diffing in our codebase, but that could well be an erroneous intuition. |
FYI: You can store raw Lisp objects inside compiled files, and you can recover them while loading compiled files. And it's an ANSI standard feature! |
In case someone else picks this PR up, I'll do a write up of what I've figured out so far: In talking with @aadcg last Thursday, he seems to think this is basically ready, but there are some issues left to fix and work to be done. The biggest issue is with writing non-serializable slots to the I'm not sure how easy or difficult the first option is, but the second one should be easier. Outside of that, there is some junk to clean up, rebase on master (which has the new |
@jmercouris if you have time, please give this branch a try and provide a report. With regards to the theme, it's trivial to fix it. The slot value |
There is too much wrong with this, and the system in general. I suggest /not/ merging this pull request. I need more time to think about how to do things properly. Possibly from the ground up. |
Let's keep the branch then. I'd suggest opening/reviewing issues on this topic and report what this iteration got right and wrong. |
Description
This is a continuation of (a part of) #2408.
Add a
setting
package for defining and applying configuration of Nyxt.A setting can update a target class (by changing a slot value or by applying an arbitrary function to it) in the following places:
This should provide a solid, convenient and testable back-end for configuring Nyxt.
Resolves #2296.
Discussion
Right now, I'm working on properly finding a writer for a slot. There is the
closer-mop:slot-definition-writers
function, but that only works for direct slots, meaning that, for example, it doesn't work very well forweb-buffers
, since most of its slots are inherited.cc @Ambrevar
Checklist:
Everything in this checklist is required for each PR. Please do not approve a PR that does not have all of these items.
cd /path/to/nyxt/checkout git submodule add https://gitlab.common-lisp.net/nyxt/py-configparser _build/py-configparser
:documentation
s written in the aforementioned style. (It's OK to skip the docstring for really trivial parts.)changelog.lisp
with my changes if it's anything user-facing (new features, important bug fix, compatibility breakage).migration.lisp
entry for all compatibility-breaking changes.(asdf:test-system :nyxt)
and(asdf:test-system :nyxt/gi-gtk)
) and they pass.