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

Make it possible to pre-load module options #39

Open
uliska opened this issue Jul 9, 2018 · 2 comments
Open

Make it possible to pre-load module options #39

uliska opened this issue Jul 9, 2018 · 2 comments

Comments

@uliska
Copy link
Contributor

uliska commented Jul 9, 2018

loadModule first tries to load a module and then applies the options to it.

In some cases it may be preferrable to have the options already set when loading the module. For example: scholarly.annotate consist/s the engraver to all bottom contexts upon loading. It would be good to have an option that chooses which contexts to use or avoid. But this works only when the options have already been set.

Idea (implementation is clear, but I'm not 100% sure if it's good design):

  • Look for a config.ily file in the module directory. if that is present:
    • load the config
    • set options if given in the \with {} block
  • Load the module
  • if no config was present set the options now

Possible problems:

  • feels somewhat fragile and hard-to-document-clearly
  • Prohibits any code in config.ily to depend on the module itself.

Slightly less invasive:

  • check if a pre-config.ily file is present.
  • set all options before loading the module that are already present in the module's option leaf.

Problem: maybe even more unclear?

@uliska
Copy link
Contributor Author

uliska commented Apr 4, 2019

Reported by a user (this is related and shows that the problem is the same on package level):

I'm currently having an apparently simple problem dealing with options.
The option I set on the loadPackage or loadModule "\with" does not take
precedence over the value used in register the options.

Eg:

%%% file: local/package.ily

\include "oll-core/package.ily"
\registerOption local.option "A"
#(display (getOption '(local option)))

%%% end

%%% file: whatever/project.ly

\include "oll-core/package.ily"
\loadPackage \with {
	option = "B"
} local

%%% end

-- Outputs: "A"

I've came up with a workaround, but then I tought that is most likely I just
don't know how to proper handle it. "\registerDefaultOpt" is a simple
function that only register the value if the option is unregistered.

%%% file: local/package.ily

\include "oll-core/package.ily"
\registerDefaultOpt local.option "A"
#(display (getOption '(local option)))

%%% end

%%% file: whatever/project.ly

\include "oll-core/package.ily"
\registerOption local.option "B"
\loadPackage local

%%% end

-- Outputs: "B"

@uliska
Copy link
Contributor Author

uliska commented Apr 4, 2019

I think the following alternative approach is cleaner. (\loadModule should be considered synonymous to \loadPackage here):

  • \loadModule stores any given options in a global place like \setOption options.current-module-loading ...
  • A function, say \applyModuleOptions, is added that reads these global "current" options and sets them

This makes it possible for a module to first register its options with default values and then (if the specific module wants to do so) take the options given by the user to override the defaults. These user-provided values are then available during the loading of the module/package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant