Run Tool on Selection Only

Ideas for new features

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
ds0934
Posts: 41
Joined: Thu Nov 18, 2004 2:06 pm
Location: Virginia, USA
Contact:

Run Tool on Selection Only

Post by ds0934 »

I'm sure this might not fit with all languages, but it would be nice to be able to highlight a section of code (maybe one routine or block) and run it with a selected Tool to view the results. Rather than running the tool against the entire file, just run it against what is selected.
User avatar
Mr. Code Monkey
Posts: 24
Joined: Thu Jul 30, 2009 4:59 am

Post by Mr. Code Monkey »

Agreed; that would be handy.
H. Camphausen
Posts: 2
Joined: Mon Dec 07, 2009 5:38 pm

Post by H. Camphausen »

Hmm, not too far ago I wrote a little script to achive just this. The script is written in Perl (and aimed to run "Perl snippets"), but adopting the script to run arbitrary programs shoud not be too hard.

I invoke the script as a TextPad custom tool.

Prerequisites:
- a working installation of Perl (available at www.activestate.com)
- the Perl module Win32::Clipboard (part of ActiveState's Perl package)

If you are interested, just leave a note.
User avatar
Mr. Code Monkey
Posts: 24
Joined: Thu Jul 30, 2009 4:59 am

Post by Mr. Code Monkey »

H. Camphausen wrote:Hmm, not too far ago I wrote a little script to achive just this. The script is written in Perl...
Sounds useful. Can you not paste the script here using

Code: Select all

a code box?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Have a look at my Perl script at the end of http://forums.textpad.com/viewtopic.php?t=4890&start=15 (2006-04-19).

This method of implementing a script to manipulate a document in TextPad is a far from satisfactory. Such a script is tricky to write, it runs too slowly, and because of it works by sending keystrokes to TextPad, it requires you not to type anything while it's running.

TextPad's usefulness would be much increased if it provided a programming interface and supported scripts that use it.
H. Camphausen
Posts: 2
Joined: Mon Dec 07, 2009 5:38 pm

Post by H. Camphausen »

@Mr. Code Monkey:

It's been a while now, but here you go ... well, no code box (looked ugly), just a link (two, actually):

http://www.textix.de/perlix/index.htm
http://www.textix.de/perlix/perl.runsnippet.zip

No doc available, sorry. (Except for a few hints within the script.)

Cheerio, H.
User avatar
Mr. Code Monkey
Posts: 24
Joined: Thu Jul 30, 2009 4:59 am

Post by Mr. Code Monkey »

H. Camphausen wrote:@Mr. Code Monkey:

It's been a while now, but here you go ... well, no code box (looked ugly), just a link (two, actually):

http://www.textix.de/perlix/index.htm
http://www.textix.de/perlix/perl.runsnippet.zip

No doc available, sorry. (Except for a few hints within the script.)

Cheerio, H.
Thank you.
I'll see if I can't gin up a python version one of these days.
User avatar
trids
Posts: 69
Joined: Wed May 07, 2003 10:16 am
Location: South Africa

Post by trids »

I have created a tool to do precisely this .. and it's available as a TextPad Add-on :D Although this add-on (mysl3.zip) runs your text selection as a SQLite3 script/query, it can easily be modfied to execute your selection as any other language that has a commandline interface. Eg: AutoIt3, Python, etc

In fact, i do have another one which uses the same approach that runs python selections, but have not as yet sent it in for inclusion with the add-ons. I will repost here once I have -- it might make it easier to see how to clone and modify it for whatever language you want to support, when you have two examples to compare.

Meantime, you can take a look at the fully documented SQLite3 one (msyl3.zip, above), and see if you can modify it yourself for your preferred language.
:wink:

edit: typos
Post Reply