[NEW plugin] TW5 Search and Replace

941 views
Skip to first unread message

Danielo Rodríguez

unread,
Apr 9, 2015, 4:32:52 PM4/9/15
to tiddl...@googlegroups.com

Hello,

I was creating a tool to make text batch processing (comparison, cleaning, getting unique values,etc) using TW as backend and I realized that some parts could be packed into a plugin. Basically we can say that I have created a plugin by mistake :P


It is a very simple plugin that allows you to search and replace text inside a tiddler. The plugin adds a controls bar in the default edit template that allows you to make some basic search and replace tasks. Of course you can build more powerful things using some of the pieces the plugin provides, but I don't have time to document it right now.


Check it out at:





Any ideas or suggestions are welcome as usual.

Jeremy Ruston

unread,
Apr 9, 2015, 4:49:10 PM4/9/15
to TiddlyWiki
Hi Danielo

Excellent, that's very neat - well done.

When I tried it out I misunderstood the "Global" option to mean that the operation would apply to all tiddlers. From the code I can see that isn't the case, but I do wonder if now that you're tantalisingly close to a true global search and replace, perhaps the option should be relabelled. Actually, I wonder if there is ever a situation where one would want it unchecked? Perhaps it can be removed entirely.

A minor point, but you're still exporting the name of the startup module as "password".

Best wishes

Jeremy.

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/994c0f91-dc37-4b0f-9f0f-dcbe285fda18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Danielo Rodríguez

unread,
Apr 9, 2015, 5:30:44 PM4/9/15
to tiddl...@googlegroups.com, jeremy...@gmail.com


El jueves, 9 de abril de 2015, 22:49:10 (UTC+2), Jeremy Ruston escribió:
Hi Danielo

Excellent, that's very neat - well done.

Thank you Jeremy, encouraging as usual.
 
When I tried it out I misunderstood the "Global" option to mean that the operation would apply to all tiddlers.
I tried to briefly explain it on the Hello There tiddler. Maybe you could suggest a better name? Multiple? All?
 
 but I do wonder if now that you're tantalisingly close to a true global search and replace,
I'm not sure about that. I think that a true global search and replace could involve some better logic.

 
perhaps the option should be relabelled.

Definetivelly
 
Actually, I wonder if there is ever a situation where one would want it unchecked? Perhaps it can be removed entirely.


Sometimes people only want to replace the first occurrence.  For that cases it makes sense.

Ooops. I used it for the headers. Already fixed. Thank you. 

Jeremy Ruston

unread,
Apr 10, 2015, 3:53:26 AM4/10/15
to Danielo Rodríguez, TiddlyWiki
Hi Danielo

Perhaps the clearest thing would be to replace the checkbox with a select widget with two options "First occurrence only" and "All occurrences"?

Best wishes

Jeremy

Danielo Rodríguez

unread,
Apr 10, 2015, 10:31:35 AM4/10/15
to tiddl...@googlegroups.com, rdan...@gmail.com, jeremy...@gmail.com
I just released a new version.

It allows to use regular expressions to search and replace, which is much more powerful. 
check it out at 


Jeremy, regarding the  naming issue: I realized that the current implementation and even your proposal takes the same space as another button will do. So I think I will end up with a button for single replace labelled replace and another button labelled replace all. Most of search and replace menus works this way so I think it makes sense.

Jeremy Ruston

unread,
Apr 10, 2015, 11:25:41 AM4/10/15
to Danielo Rodríguez, TiddlyWiki
Hi Danielo

Jeremy, regarding the  naming issue: I realized that the current implementation and even your proposal takes the same space as another button will do. So I think I will end up with a button for single replace labelled replace and another button labelled replace all. Most of search and replace menus works this way so I think it makes sense.

That's a great idea, much better.

Best wishes

Jeremy

Danielo Rodríguez

unread,
Apr 10, 2015, 1:03:03 PM4/10/15
to tiddl...@googlegroups.com, rdan...@gmail.com, jeremy...@gmail.com
Hello Jeremy,

May you can help me with this. I have tried to use some special characters on the replace field (\n,\t etc) and I expected it to work. But it is not working, and I can't understand why. If I do any javascript replace on the console it works. I even tried using some TW functions on console like setText and it works at expected.

$tw.wiki.setText("$:/temp/col-a",null,null,$tw.wiki.getTiddlerText("$:/temp/col-a").replace(/\n/g,"\n\n"))

But I don't understand why it is not working when the "daemon" does the replacement. Hope you can figure it out.

Jeremy Ruston

unread,
Apr 12, 2015, 8:49:57 AM4/12/15
to Danielo Rodríguez, TiddlyWiki
Hi Danielo

May you can help me with this. I have tried to use some special characters on the replace field (\n,\t etc) and I expected it to work. But it is not working, and I can't understand why. If I do any javascript replace on the console it works. I even tried using some TW functions on console like setText and it works at expected.

$tw.wiki.setText("$:/temp/col-a",null,null,$tw.wiki.getTiddlerText("$:/temp/col-a").replace(/\n/g,"\n\n"))

But I don't understand why it is not working when the "daemon" does the replacement. Hope you can figure it out.

Please can you point to the code?

Best wishes

Jeremy
 

Danielo Rodríguez

unread,
Apr 13, 2015, 2:09:27 AM4/13/15
to tiddl...@googlegroups.com, rdan...@gmail.com, jeremy...@gmail.com
Please can you point to the code?

J Mc

unread,
Mar 21, 2017, 3:43:46 PM3/21/17
to TiddlyWiki, rdan...@gmail.com, jeremy...@gmail.com
Hi Danielo,
I have tried your searchNreplace plugin but can't get it to work.
I have a large list of street names which I need to enclose in square brackets and need to separate with a blank line so that I can create new tiddlers from a list.
I can search for \n and replace this [[ but can't put the closing ]] brackets in place.
If I have a list such as below,

Abbey Close
Abbey Lane
Abbey Mount
Abbey Strand
Abbey Street


how do I achieve the following

[[Abbey Close]]

[[Abbey Lane]]

[[Abbey Mount]]

[[Abbey Strand]]

[[Abbey Street]]

Any help you could offer would be great much appreciated.

Thanks,

J Mc

Danielo Rodríguez

unread,
Mar 22, 2017, 7:59:54 AM3/22/17
to TiddlyWiki, rdan...@gmail.com, jeremy...@gmail.com
Hello J Mc,

You should be able to get wat you want making use of the regular expression feature.

Hope the following screenshots helps you, let me know if it does not:

J Mc

unread,
Mar 22, 2017, 11:04:30 AM3/22/17
to TiddlyWiki, rdan...@gmail.com, jeremy...@gmail.com
Hi Danielo,
I have tried the regular expression suggested in your screenshot, but it does not work. It is close, but not exactly as I need it.

The results is as shown below.

[[Abbey]] [[Close]]

[[Abbey]] [[Lane]]
[[Abbey]] [[Mount]]
[[Abbey]] [[Strand]]
[[Abbey]] [[Street]]

The result that I need is as shown below. (Please note the blank lines in between each street name).


[[Abbey Close]]


[[Abbey Lane]]

[[Abbey Mount]]

[[Abbey Strand]]

[[Abbey Street]]

Thanks for your help.
J Mc

Danielo Rodríguez

unread,
Mar 22, 2017, 11:16:47 AM3/22/17
to TiddlyWiki, rdan...@gmail.com, jeremy...@gmail.com
Dear J Mc,

You are probably missing the whitespace between the braces. Note the regular expression is ([A-z ]+), with a space after the z

Regards

J Mc

unread,
Mar 22, 2017, 11:40:28 AM3/22/17
to TiddlyWiki, rdan...@gmail.com, jeremy...@gmail.com
Danielo,

That's what was wrong. I didn't notice the space after the z.
It worked perfectly.
Thank you very much. This will save me quite a lot of time preparing this and other such lists.
Best regards,

J Mc

Danielo Rodríguez

unread,
Mar 23, 2017, 8:40:24 AM3/23/17
to TiddlyWiki, rdan...@gmail.com, jeremy...@gmail.com
Glad it finally worked

David Szego

unread,
Mar 23, 2017, 9:12:32 PM3/23/17
to TiddlyWiki, rdan...@gmail.com, jeremy...@gmail.com
Danielo, really nice work. Can I suggest you turn it into an editor button to reveal/hide the existing UI? It would be less intrusive than the always-present bar you have now.

Cheers,
David.

On Thursday, 23 March 2017 08:40:24 UTC-4, Danielo Rodríguez wrote:
Glad it finally worked

Danielo Rodríguez

unread,
Mar 24, 2017, 3:17:20 PM3/24/17
to TiddlyWiki
Dear David,

That's a good suggestion. However, this plugin is quite old, and it is previous to the editor bar. I don't have experience with it, so I don't know how easy or hard would be to integrate it .

Reply all
Reply to author
Forward
0 new messages