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

[Feature] Option for explicitly enabling Qalc in non .qalc documents #35

Closed
janogarcia opened this issue Feb 27, 2024 · 5 comments
Closed

Comments

@janogarcia
Copy link

janogarcia commented Feb 27, 2024

Thanks, Nick, for such a cool, useful extension!

For non .qalc documents, like Markdown, it would be awesome if we had a setting for enabling Qalc for specific blocks instead of parsing the entire document by default.

This increased granularity would prevent Qalc from unnecessarily parsing entire, large Markdown documents and, simultaneously, prevent it from doing unwanted calculations.

Making this available as a setting would be super welcome.

Example using HTML comments:

# Aggregations
1
2
3
4
sum
avg

# Dates
<!-- qalc:on -->
3/14/2021 11:21:56 PM UTC
date(3/14/2021)
date(1615789316)
date(1615789316000)
yesterday
tomorrow
today
now
1 year in months
now - 3 days
3 days ago
<!-- qalc:off -->

# Variables and Objects
variable = 7
object = {field: 2}
object.field * variable

Alternatively, using code blocks could be even cleaner:

# Aggregations
1
2
sum
avg

# Dates
```qalc
3/14/2021 11:21:56 PM UTC
date(3/14/2021)
date(1615789316)
```

# Variables and Objects
variable = 7

Live test using //qalc:off and //qalc:on by setting let qalcEnabled = false; by default in MathDocument::evaluate():

let qalcEnabled = true;

SCR-20240227-pldl
@nortakales
Copy link
Owner

nortakales commented Feb 28, 2024

For the sake of this discussion let's define a couple terms:

  1. Enabled/disabled - whether or not Qalc looks at or does anything at all with a file
  2. Processing on/off - whether or not Qalc is processing a specific line and outputting results

I am trying to think of how best to implement this from a user perspective. I can see at least two options:

  1. Qalc will be enabled by default for all files, but processing will be on by default for only file types listed in qalc.enabledLanguages, and otherwise will be off by default with the ability to turn it on for sections via //qalc:on
  2. qalc.enabledLanguages will exist as is and control the file types Qalc is enabled for, and there can be a new setting(s) to control which files or file types have processing on/off by default.

I think # 2 gives a little more flexibility and maybe some performance gains as you can tell Qalc which files types to look at and to completely ignore certain file types (rather than searching for //qalc:on in all files)

@janogarcia
Copy link
Author

janogarcia commented Feb 28, 2024

Thanks for considering this feature request!

If by # 1 you mean having the ability to invoke //qalc:on universally on any arbitrary file type (even those not included in qalc.enabledLanguages), that’s probably not a common use case I would anticipate, and paired with the potential performance penalty doesn’t seem like the best choice.

Overall, # 2 could be the best tradeoff — less magic and more explicit/intentional without the performance penalty.

@janogarcia
Copy link
Author

janogarcia commented Feb 28, 2024

If you don’t want to overcomplicate the user settings and keep qalc.enabledLanguages as is, you could even consider starting out with just a checkbox. For example:

  • Explicit Activation
    When turned on, Qalc will only be active between //qalc:on and //qalc:off delimiters. This setting does not apply to .qalc documents, which are automatically processed. It affects only other supported languages, such as "markdown" and "plaintext".

It should be easier to maintain from a user perspective. Set enabled languages, mark checkbox, and done, without needing to keep track of a second array of languages.

In the event you want to turn that checkbox into an array in the future for even added granularity, it should be straightforward to automate that migration.

Just an idea.

@nortakales
Copy link
Owner

Addressed in version 0.4

@janogarcia
Copy link
Author

Awesome, thanks for adding support for it!

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

No branches or pull requests

2 participants