Re: Easiest way to replace all matches

2021-10-25 Thread John Delacour


On 21 Oct 2021, at 12:47, TJ Luoma mailto:luo...@gmail.com>> 
wrote:

> I'd like to be able to select a word, press a key, and have all instances of 
> that word be surrounded by {brackets} I wondered if there was a more 
> native way to accomplish this

#!/usr/bin/perl
while (<>) {
s~myword~{$&}~ig;
print;
} #END

The script
• reads the document line by line,
• surrounds all (~g) occurrences of "myword" (case-insensitive ~i) with curly 
brackets,
• prints the line.

Instructions:

Save the script in the Text Filters folder as ***.pl 
( Terminal:— cd; open Library/Application\ Support/BBedit/Text* )
Open the palette:  Menu: Window::Palettes::Text Filters
Select the script and set an optional keyboard shortcut
With your document frontmost, run the script
You can undo the action of the UNIX filter but…
… to see the result without altering the doc, run the script from the Scripts 
folder+palette

JD


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/99376642-B69E-4477-8090-519AC6668FCE%40gmail.com.


Re: Easiest way to replace all matches

2021-10-22 Thread TJ Luoma
> That's not overly difficult using a bit of AppleScript.

Well, not for you, maybe!

Thanks! That's probably something simple enough that I can build on it, too!

TJ



On Thu, Oct 21, 2021 at 11:40 AM Christopher Stone 
wrote:

> On Oct 21, 2021, at 06:47, TJ Luoma  wrote:
>
>
> Assume a 'regular' text file.
>
> I'd like to be able to select a word, press a key, and have all instances
> of that word be surrounded by {brackets}.
>
> --
>
> Hey Tj,
>
> That's not overly difficult using a bit of AppleScript.
>
> --
> Take Care,
> Chris
>
> --
>
> 
> # Auth: Christopher Stone 
> # dCre: 2021/10/21 10:33
> # dMod: 2021/10/21 10:33
> # Appl: BBEdit
> # Task: Enclose All Instances of the Selected Word with Curly Braces.
> # Libs: None
> # Osax: None
> # Tags: @Applescript, @Script, @BBEdit, @Enclose,@Instances, @Selected,
> @Word, @Curly, @Braces
> 
>
> *tell* *application* "BBEdit"
> *tell* *front* *text window's* *text*
> *set* theWord *to* *the* selection *as* *text*
> *set* rePattern *to* "\\b" & theWord & "\\b"
> *replace* rePattern using "\\{&\\}" options {search mode:*grep*, case
> sensitive:*false*, starting at top:*true*}
> *end* *tell*
> *end* *tell*
>
> 
>
> --
> This is the BBEdit Talk public discussion group. If you have a feature
> request or need technical support, please email "supp...@barebones.com"
> rather than posting here. Follow @bbedit on Twitter: <
> https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to bbedit+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bbedit/0BC82778-B9FE-417A-A5B6-87CC90F9A397%40gmail.com
> 
> .
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/CADjGqHuJKENaPR5Zx8AMb0f-1RQ8wevrYNC94wMKRq22_bg9hQ%40mail.gmail.com.


Re: Easiest way to replace all matches

2021-10-21 Thread Christopher Stone
> On Oct 21, 2021, at 06:47, TJ Luoma  wrote:
> 
> Assume a 'regular' text file.
> 
> I'd like to be able to select a word, press a key, and have all instances of 
> that word be surrounded by {brackets}.

Hey Tj,

That's not overly difficult using a bit of AppleScript.

--
Take Care,
Chris



# Auth: Christopher Stone 
# dCre: 2021/10/21 10:33
# dMod: 2021/10/21 10:33 
# Appl: BBEdit
# Task: Enclose All Instances of the Selected Word with Curly Braces.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Enclose,@Instances, @Selected, @Word, 
@Curly, @Braces


tell application "BBEdit"
tell front text window's text
set theWord to the selection as text
set rePattern to "\\b" & theWord & "\\b"
replace rePattern using "\\{&\\}" options {search mode:grep, case 
sensitive:false, starting at top:true}
end tell
end tell



-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/0BC82778-B9FE-417A-A5B6-87CC90F9A397%40gmail.com.


Easiest way to replace all matches

2021-10-21 Thread TJ Luoma
Assume a 'regular' text file.

I'd like to be able to select a word, press a key, and have all instances
of that word be surrounded by {brackets}.

For this example,  the words would all be names so you would not need worry
about "What if the word is {and} but the word "br{and}s" also exists?

I could hack this together with Keyboard Maestro but I wondered if there
was a more native way to accomplish this

Thanks for your help!

~ Tj

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/CADjGqHtLTnoECLX4J44LvkAVdG2P1JpCUmg3%2ByCNqbP_NmjX3A%40mail.gmail.com.