Open dgw opened 8 years ago
That looks like a great plugin, but I wouldn't enable it for the main instance. It does complicate the syntax, and would underweight these folded tidbits in comparison to others.
That said, it does degrade gracefully, and I don't think it would break many existing factoids.
I see your point about underweighting the new folded tidbits, but I'm not going to worry about it too much because the intended use case is to replace factoids that currently have several slight variations with just one folded factoid.
With regard to breaking existing factoids, it might be better to use {{double braces}}
, like MediaWiki transclusions or Liquid output tags. Is there a dump of the main instance's database (from any time in the past year, probably) that I could query for potential conflicts with different syntax ideas? My instance is nearing 6k factoids, but that's nothing compared to the main one.
out of ~140k factoids, about 5 will be affected.
Still think it should be a plugin though, not on by default -- both for avoiding unneeded complexity in the main code, and also to make it easy to enable/disable.
3,750 lines of code and we're worried about the added complexity of maybe a dozen more, lol.
No matter. I wrote this plugin tonight. Had to add a new plugin signal in &expand
because I couldn't wrap my head around how it might be done using the existing db_success
signal. If there's a way, I'm happy to rewrite my plugin and drop the new signal. Otherwise, expect a PR for the new signal soon, but I'll want to battle-test the plugin for a good while (think weeks) before submitting it for inclusion.
I've a couple questions regarding this when you have a moment, @zigdon.
Whatever the answer to question 2, if the answer to question 1 is "Yes", I'm happy with the plugin as-is and ready to open a PR for review.
This is a working draft, and may be revised based on feedback in the comments. Where appropriate, I will note if a change has been made.
Use case
Avoiding the creation of multiple, nearly identical factoids while still providing more variety than a single factoid under the current system.
Example
Replace this list of tidbits for the same trigger:
with this single factoid:
Note that the list of factoids would double in size from 12 entries to 24 if, for example, it was also desired for Bucket to possibly say "I will $verb the $noun!" etc. With the proposed syntax, that could be folded into the example with
=~ s/not/{not|}/
.Why new syntax
This behavior can sort of be implemented by creating variables. The drawbacks are:
New syntax would eliminate these drawbacks, respectively, as follows:
||
) or an empty alternative at the beginning or end of the list ({|
or|}
) represent a variation where that element does not appear (with multiple consecutive spaces collapsed before output).One of the obvious arguments against this is that it would make the syntax for teaching Bucket even more arcane. In an effort to use something reasonably intuitive, I've proposed curly braces and pipes in this example. Pipes are intuitive regex "or" syntax, and curly braces appear in string interpolation when using languages like PHP—whose $variables Bucket's vars resemble in text. But the syntax is up for discussion just as much as whether to implement the idea.
Implementation considerations
$noun{s|}
at end of example).{list|of|options}
) and/or the number of blocks allowed per factoid (as variables are)?Status
master
) to resolve the variation syntax before variables are expanded.|
if it is escaped with\
:{variations|can|contain\|pipes|by escaping}
yields the candidates["variations", "can", "contain|pipes", "by escaping"]
.split
routine that ignored empty variations at the tail of the block (since fixed).pre_expand
) was merged tomaster
back in May.