[TW5] AutoCorrectPlugin: Any Equivalent for Replacing Text Strings

185 views
Skip to first unread message

Scott Simmons

unread,
Dec 31, 2015, 10:05:46 AM12/31/15
to tiddl...@googlegroups.com
One of the plugins I came to rely heavily on in TiddlyWiki Classic was Simon Baird's AutoCorrectPlugin, which allowed you to create a tiddler (or tiddlers) specifying words/strings you wanted TiddlyWiki to replace when it came across them during a save-tiddler operation.  When you committed changes to a tiddler, any text you'd entered that matched a string in one of your autocorrect lists would be replaced before the tiddler was saved.

The basic use was for correcting misspellings (e.g., mispelling->misspelling), but you could also use it to deploy complex text strings you didn't want to type every time (e.g., myLicenseKey->ACompleteStringOfNumbersAndLettersA@1X57T4E).

Has anyone created a similar plugin for TiddlyWiki5?

Tobias Beer

unread,
Dec 31, 2015, 10:30:36 AM12/31/15
to tiddl...@googlegroups.com
Hi Scott,

Can you be a little more specific as to what the biggest pain points are
for you to wanting an AutoCorrectPlugin for TW5?

To me, AutoCorrectPlugin feels a bit too much of a hybrid, tbh.

Inserting some kind of (even dynamic) template text for a timestamp, macro, widget,
and then replacing common misspellings are two entirely different tasks, me thinks.

The former, I would not want to be performed by doing some "autocorrect",
but rather by selecting from a (filterable) list and inserting at the caret position.
I want to see what is inserted before things get saved... and adjust a template as needed.

For the latter, I would possibly define one or more dictionary tiddlers
that specify a filter field to be able to constrain the tiddlers to which it applies,
and otherwise specify indexes that are...
  • simple words
    • replaced as is
  • /regex/mgi
    • to auto-replace more sophisticated things
Whereas the values represent the replacement text... which — for current DataTiddlers — would be one-liners only ...but could perhaps — for inserting multi-line content — leverage a syntax that instructs the replacing algorithm to go fetch the content from a text-reference instead.

Also, I'd want any auto-correcting to inform me whenever it does something, perhaps in a modal... so I can confirm (for each instance) that "Yes, please proceed replacing".

Best wishes,

Tobias.

Scott Simmons

unread,
Dec 31, 2015, 11:07:16 AM12/31/15
to tiddl...@googlegroups.com
On Thursday, December 31, 2015 at 10:30:36 AM UTC-5, Tobias Beer wrote:
 
Inserting some kind of (even dynamic) template text for a timestamp, macro, widget,
and then replacing common misspellings are two entirely different tasks, me thinks.

Makes sense.  While I might not immediately want more complex functions from the first hypothetical plugin, I can see where having the ability to (say) insert a timestamp would create a desire for them (in me and in others).
 
For the latter, I would possibly define one or more dictionary tiddlers
that specify a filter field to be able to constrain the tiddlers to which it applies,
and otherwise specify indexes that are...
  • simple words
    • replaced as is
The prevalence of dictionary tiddlers in TW5 makes managing and sharing such autocorrect lists more natural than in TWC.  Actually making the replacements on saving/committing a tiddler remains as much of a mystery to me in TW5 as it did in TWC.
  • /regex/mgi
    • to auto-replace more sophisticated things
Whereas the values represent the replacement text... which — for current DataTiddlers — would one-liners only ...but could perhaps — for inserting multi-line content — leverage a syntax that instructs the replacing algorithm to go fetch the content from a text-reference instead.

That sounds more like the fantasy project I outlined in my follow-up thread — which is completely beyond my abilities.  (But something that would have quite a bit of use for me, I think.  This might be some custom work I'd be interesting in helping to fund if anyone else sees the utility of it.)

Your reference to /regex/mgi was lost on me, I'm afraid.  Is that a directory? pragma? library? TW tag? plugin?

Tobias Beer

unread,
Jan 1, 2016, 6:04:20 AM1/1/16
to TiddlyWiki
Hi Scott,
  
Your reference to /regex/mgi was lost on me, I'm afraid.  Is that a directory? pragma? library? TW tag? plugin?

I simply tried to hint at wanting to express regexp patterns... that generally look like that, whereas the things within the two forward slashes and after the 2nd vary depending on your pattern. The tricky bit would be a pattern to replace identified capture groups in the replacement text. You may quickly need a function to do that, which we obviously can't quite do in a dictionary tiddler... unless we did some "eval this replacement value"... which we probably better not. ;-)

So, if we had not only a replacement string but a very rudimentary support for capture groups and corresponding placeholders in the output that would be great, so we can do...

/a pattern (group 1) and (group 2)/mgi: <$some-widget attr="""$1$""">$2$</$some-widget>

Actually, without placeholder support using regexp patterns would be rather limited.

Best wishes,

Tobias. 

Scott Simmons

unread,
Jan 2, 2016, 7:21:41 AM1/2/16
to TiddlyWiki
On Friday, January 1, 2016 at 6:04:20 AM UTC-5, Tobias Beer wrote:
  
Your reference to /regex/mgi was lost on me, I'm afraid.  Is that a directory? pragma? library? TW tag? plugin?

I simply tried to hint at wanting to express regexp patterns... that generally look like that, whereas the things within the two forward slashes and after the 2nd vary depending on your pattern.

Oh!  I knew I was being dense about something, but I couldn't figure out what.  :P
 
The tricky bit would be a pattern to replace identified capture groups in the replacement text.

The more I dwell on it, the more I realize I'm wishing for two separate solutions (just as you grokked in your first reply):
  1. A modern, TW5 version of AutoCorrectPlugin, which would poll a user-configurable set of dictionary tiddlers to make on-the-fly replacements to text in the input field of a tiddler in Edit view before its committed.
  2. A more complex tool for streamlining repeated inputs with regex transformations.
Maybe the thing to do is keep this thread dedicated to #1 and continue discussing #2 in that other thread I started.  For one thing, a modern AutoCorrect replacement may be of greater interest to the TW community at large.  For another, it seems like it would be a relatively manageable project for someone who understands the mechanics of moving text from draft to the body of a saved tiddler in TW5. 

The other project might be a good expansion on these principles, though it would involve more tinkering and testing, and I'm not sure how popular it would be with the TW community large — though, of course ,*I* think it would be immensely useful to anyone who drop text into TWs from other places.  :)

For the AutoCorrect plugin, it seems to me it should reach into a user-configurable list of dictionary tiddlers for its term/definition pairs (where term = text to be replaced, definition = replacement text).  Users could point to their own tiddler, multiple tiddlers, or a whole-macro-fetched set of tiddlers like <$list filter="[tag[$:/plugins/AutoCorrect/lists]sort[title]]" /> or <$list filter="[prefix[AutoCorrectWords_]sort[title]]" /> [1]).

(I include the sort operator because you'd want some predictability in replacments.  See here for an example related to the old autocorrect plugin.)

You could initially include a shadow tiddler [$:/plugins/AutoCorrect/list (?)] defining a single example pair (mispelling : misspelling).

There should also be some way to specify exceptions to where autocorrection occurs.  In Simon's original plugin, this was done by adding a tag (excludeWikiWords) to tiddlers you wanted to exclude from the plugin's reach.  Given the extended capabilities of TW5, though, I imagine this could also be a setting in the plugin, configurable in the same way as the list of dictionary tiddlers.  (E.g., a list of tiddlers or a macro call like <$list filter="[tag[excludeWikiWords]prefix[$:/]]" />.)  These two settings would allow users great flexibility in deciding how to use such a plugin and apply it judiciously to their content.

[1] My ignorance is really showing here, as I have no idea how to properly generate such a list to pass into another script in TW5.

Tobias Beer

unread,
Jan 3, 2016, 10:57:43 AM1/3/16
to tiddl...@googlegroups.com
Hi Scott,
 
(I include the sort operator because you'd want some predictability in replacments.  See here for an example related to the old autocorrect plugin.)

Actually, if you wanted predictability, the mechanism will do no sorting whatsoever but walk through the indexes in the very sequence they are specified in the dictionaries. As for dictionaries themselves, the list field of the corresponding system-tag would declare precedence of one dictionary over the other.

There should also be some way to specify exceptions to where auto-correction occurs.

I think each dictionary should have a filter field that specifies what tiddlers a given dictionary applies to.

In Simon's original plugin, this was done by adding a tag (excludeWikiWords) to tiddlers you wanted to exclude from the plugin's reach.  Given the extended capabilities of TW5, though, I imagine this could also be a setting in the plugin, configurable in the same way as the list of dictionary tiddlers.  (E.g., a list of tiddlers or a macro call like <$list filter="[tag[excludeWikiWords]prefix[$:/]]" />.)

I don't see such a plugin using list widgets but rather query the wiki for replacement definitions in dictionary tiddlers directly (using js). So, any configurations will have to be bound to the dictionaries themselves, I think. Therefore, the only true option I see right now is the filter field.

Best wishes,

Tobias.

Secret-HQ

unread,
Jan 4, 2016, 10:54:01 AM1/4/16
to TiddlyWiki
On Sunday, January 3, 2016 at 10:57:43 AM UTC-5, Tobias Beer wrote:

(I include the sort operator because you'd want some predictability in replacments.  See here for an example related to the old autocorrect plugin.)

Actually, if you wanted predictability, the mechanism will do no sorting whatsoever but walk through the indexes in the very sequence they are specified in the dictionaries. As for dictionaries themselves, the list field of the corresponding system-tag would declare precedence of one dictionary over the other.

Funny you should mention that, as I'm still struggling to come to grips with the list field and often forget about its ordering power.  (Whenever I do remember it, it seems to be in some context where it won't solve my immediate problem — at least in any way I can yet see.  ;)  )
 
There should also be some way to specify exceptions to where auto-correction occurs.

I think each dictionary should have a filter field that specifies what tiddlers a given dictionary applies to.

Hmmmm.  Wouldn't it be easier to define the set of affected (or unaffected) tiddlers in one place, rather than having to do so every time you create a new dictionary?

In my case, with TWC, I created new autocorrect lists pretty regularly — and applied them all in the same circumstances.  I.e., if there was a tiddler where I didn't want autocorrection, I didn't want ANY autocorrection.  Instances where I might want SOME autocorrections but not OTHER autocorrections didn't come up.  Even with that ability, I can't imagine that circumstance rearing its head often — but maybe others feel differently.

For example, I used the old autocorrect plugin to expand on episode titles for TV shows.  I'd scrape the titles of episodes from Wikipedia or TV.com and run a saved macro in N++ (outside of TW) to give me a set of matched autocorrect pairs that I could drop into a new tiddler.  Individual lines there looked something like this:  BBad:Felina->//Breaking Bad// season 5, episode 16: "Felina"  That allowed me to drop shorthand into my journal tiddlers when I caught an episode of something and know where it fell in the overall run of a show.  (It also allowed me to reference episodes by title without having to look up seasons and episode numbers when writing something about a show.)

The TV example may not be especially relevant — but it does demonstrate a case where someone might want to create individual dictionary tiddlers more or less on the fly without having to do a lot of configuration (or updating the list field of the master-tag tiddler).
 
I don't see such a plugin using list widgets but rather query the wiki for replacement definitions in dictionary tiddlers directly (using js). So, any configurations will have to be bound to the dictionaries themselves, I think. Therefore, the only true option I see right now is the filter.

Maybe the dictionary tiddlers could transclude settings from a $:/plugins/autocorrect/settings tiddler?  That would allow for customizatons in individual dictionaries (by referencing a different, user-created tiddler or by entering settings directly into the dictionary instead of a transclusion) while still allowing for central settings.

(Sorry if these suggestions are far afield from how TW5 does things.  Despite my efforts to learn, it feels like I'm freshly ignorant about TiddlyWiki all over again since taking the TW5 plunge.)

Tobias Beer

unread,
Jan 4, 2016, 2:33:49 PM1/4/16
to TiddlyWiki
Hi Scott,
 
Funny you should mention that, as I'm still struggling to come to grips with the list field and often forget about its ordering power.  (Whenever I do remember it, it seems to be in some context where it won't solve my immediate problem — at least in any way I can yet see.  ;)  )

As for the list field, to have it do its "magick" you literally need to use the tagging[] filter. As far as I know no other filter will sort titles based on the list field ..and some other, well, list-field.

I think each dictionary should have a filter field that specifies what tiddlers a given dictionary applies to.

Hmmmm.  Wouldn't it be easier to define the set of affected (or unaffected) tiddlers in one place, rather than having to do so every time you create a new dictionary?

Yes, maybe... but how many dictionaries are we going to have? How much trouble would it be to copy over your filter from one to the other?
 
In my case, with TWC, I created new autocorrect lists pretty regularly — and applied them all in the same circumstances.  I.e., if there was a tiddler where I didn't want autocorrection, I didn't want ANY autocorrection.  Instances where I might want SOME autocorrections but not OTHER autocorrections didn't come up.  Even with that ability, I can't imagine that circumstance rearing its head often — but maybe others feel differently.

It really depends on what the replacement definitions in the dictionaries do. If they do complex'ish stuff and replace a placeholder with some template'ish content... then we may actually want to constrain applicability to say, to-do-list-items only. But what do I know. :D

The thing with a "global filter" would be that you would need "yet another tiddler" to specify that filter.

For example, I used the old autocorrect plugin to expand on episode titles for TV shows.  I'd scrape the titles of episodes from Wikipedia or TV.com and run a saved macro in N++ (outside of TW) to give me a set of matched autocorrect pairs that I could drop into a new tiddler.  Individual lines there looked something like this:  BBad:Felina->//Breaking Bad// season 5, episode 16: "Felina"  That allowed me to drop shorthand into my journal tiddlers when I caught an episode of something and know where it fell in the overall run of a show.  (It also allowed me to reference episodes by title without having to look up seasons and episode numbers when writing something about a show.)

Interesting.
 
The TV example may not be especially relevant — but it does demonstrate a case where someone might want to create individual dictionary tiddlers more or less on the fly without having to do a lot of configuration (or updating the list field of the master-tag tiddler).

Mhhh, the question would be: Why would you need or want a bunch of dictionaries if you could do it all in one? I mean you can easily have bbad stuff followed by, say, dexter.

(Sorry if these suggestions are far afield from how TW5 does things.  Despite my efforts to learn, it feels like I'm freshly ignorant about TiddlyWiki all over again since taking the TW5 plunge.)

That's all good... I just feel like the more I try to accomplish things with "wikitext only"... the more I become Mr. Bricolage. Doing things in js directly makes things all the more powerful... and maintainable... rather than trying to wield that wikitext wrench.

Best wishes,

Tobias.
Reply all
Reply to author
Forward
0 new messages