Turning TextPad into an IDE for any programming language!

General questions about using TextPad

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

Post Reply
Mark Rejhon
Posts: 11
Joined: Sat Aug 07, 2004 6:36 pm
Location: Ottawa, Ontario, Canada
Contact:

Turning TextPad into an IDE for any programming language!

Post by Mark Rejhon »

Just registered TextPad (after using it for a long time, go figure -- I should have registered much earlier but my old copy was so stable and I never bothered to visit TextPad's website). I just discovered this forum.

Have been a programmer for almost 20 years, and am writing a programming-language interpretor from scratch, and am now starting to create an integrated debugger for my scripting language -- by using TextPad!

I found a way to turn TextPad into an IDE for just about any programming language I can create (or those that can attach to third party IDEs, or languages with debugger hooks, etc).

Single Stepping
Variable Watches
Breakpoints
Variable Watches
Error Highlighting

It all works in TextPad!

It only requires a small helper utility, read below...

It appears TextPad already contains a built-in API complete enough to make TextPad an IDE debugger for any custom scripting language that's ever developed.

I wrote my own custom scripting language and have full control over the interpretor source code. So far, I have found this information:

TextPad provides a DDE method for this. Execute this TextPad utility:
"C:\Program Files\TextPad 4\SYSTEM\DDEOPN32.EXE" file
with the following command line parameters.
D:\path\MyCustomScriptLanguage.SCR($Y, $X)
Replace $Y and $X with the line number and column number.
Replace the path with the actual path of file to be viewed.

I wrote a test utility that does this DDE technique of file-loading and cursor-positioning, and it actually works. For cursor positioning, I add the string (#,#) to the end of the path of the file to load, no spaces between path and the (#,#) where # is replaced by Y and X cursor coordinates in the document. If I do this DDE call while the file is loaded, the tab is automatically selected (convenient) and the cursor position is immediately moved to line Y and column X. You can use the Windows ShellExecute( ) with the above information. You can even use a Windows shortcut on your Windows desktop that automatically opens a specific document at an exact line number Y and and column X. If TextPad is already running, the document tab is created (or selected if already open). And the cursor is moved to the specified position. See how it is simple? See how it can already be used for singlestepping during IDE debugging! No need to figure out what DDE is, if you don't mind executing DDEOPN32.exe everytime you singlestep (fortunately, it's instantaneous enough)

That means I can use an external program to launch TextPad with the offending line, everytime my script interpretor finds an error with a line of code in a script. Perfect.

Even if TextPad has no other API than this, it is now already possible: I can simply use a Windows system keyhook to capture the F5, F9, F10, F11 keys (capture them in a background program that I write, even if TextPad in the foreground) to do single stepping, and do simulated breakpoints by using TextPad bookmarks. (I'd just have to keep track of which bookmarks are set and which are not. Basically, I'd capture the F9 key for setting execution breakpoints, and automate TextPad into setting a bookmark for that current line.).

ACTUALLY WORKS TODAY for all Textpad 4.x: Custom keyhook software running in the background would capture industry standard IDE keypresses:
Run - F5 - Simply execute the currently open document in my interpretor. My utility captures this keypress even if TextPad is in the foreground.
Singlestep - F10, F11 - Single step through my interpretor, and use the TextPad DDE to move the cursor to the currently-executing line of script. My utility captures this keypress even if TextPad is in the foreground.
Breakpoint - F9 - Set an execution breakpoint in my interpretor, set TextPad bookmark via simulated Ctrl+F2 keypress (for current line in TextPad, also execute TextPad's bookmark utility as a makeshift way of highlighting the current line as a breakpoint). Whenever my interpretor hits that breakpoint, it would use TextPad DDE to move the cursor to that currently-executing line of script. I can even use TextPad DDE followed by keyboard automation to re-highlight breakpoints (TextPad bookmarks) if TextPad ever gets restarted, which means bookmarks are cleared but the breakpoints are still 'set' within my own software. (My utility captures this F9 keypress even if TextPad is in the foreground.)
Variable Watch - Via Clipboard - Simply mark the text and do a Copy (Ctrl+C). This copies the current string to the clipboard, and my utility would automatically monitor the Windows Clipboard in the background, and if a variable name exists by the string in the clipboard, I would automatically pop-up a window from my utility displaying the current value of the variable highlighted)
Error Highlight - Use the existing TextPad DDE call to move the cursor onto the offending code, and display the error message via my utility. (runtime error, first compile error, etc)
Current Cursor Position - Done via spying on TextPad messages in the system-wide windows message-monitoring hook within my utility. I need my interpretor to know the current cursor position whenever doing things like setting a breakpoint, since there's no other way to monitor which lines in the text document have TextPad bookmarks (used as breakpoints)

Opinions? Is there a better way to coax TextPad to become a full interative debugger IDE, complete with breakpoints, single stepping, and variable watches? It indeed works with the aboveforementioned 'hacks', but it is faintly Rube-Goldbergish ... still much faster than writing my own IDE from scratch!!
Last edited by Mark Rejhon on Sat Aug 07, 2004 8:38 pm, edited 21 times in total.
Thanks,
Mark Rejhon
www.marky.com
(to contact me, please use the spamproof link at bottom of any page on my website)
Mark Rejhon
Posts: 11
Joined: Sat Aug 07, 2004 6:36 pm
Location: Ottawa, Ontario, Canada
Contact:

Post by Mark Rejhon »

Essential reading:

Microsoft: About Hooks
This is necessary if you want to capture keys globally. Basically, a brute-force method of overriding certain keys in TextPad. These hooks can also allow you to continually monitor the Windows clipboard (perfect for making TextPad support Variable Watch). The catch is you must use a DLL file with a shared-memory section, in order to capture keypresses globally in Windows XP, regardless of which application is in the foreground. You would use a KeyboardProc for capturing keypresses (Capture all F5,F9,F10,F11 keypresses whenever TextPad is the foreground app, by using a GetForegroundWindow() check) and you would use a MessageProc for capturing the clipboard (Capture WM_COPY and WM_CUT events in the system, or using another technique of background-monitoring of the Windows clipboard). I have written many successful system hooks, so these techniques work.
Thanks,
Mark Rejhon
www.marky.com
(to contact me, please use the spamproof link at bottom of any page on my website)
Mark Rejhon
Posts: 11
Joined: Sat Aug 07, 2004 6:36 pm
Location: Ottawa, Ontario, Canada
Contact:

Post by Mark Rejhon »

And.... if any corporations take my ideas about hooking TextPad into IDE (whether TextPad themselves, SUN, or another third party) ....please don't forget to mention my name. I'd like due credit, even if I'm not paid for this idea :) You can find my email address via my personal homepage website link at the bottom of my post.

I'm sure the TextPad people do not mind because this helps TextPad sales, if a few people decide to turn TextPad into an IDE for their own programming languages. I considered keeping this idea to myself, but I decided I should publicize that TextPad can be used as an IDE with just a little help from a custom background utility (only about 500-750 lines of code). It's the only way to add a true full debugging IDE to your own custom programming language or scripting language (that you wrote or invented) in less than 5 days -- save yourself the trouble of reinventing the wheel by writing an IDE from scratch! Just use TextPad and write a tiny helper utility to turn TextPad into a full IDE!

Although it is now finally possible for TextPad to now be a true self contained IDE (all the way back to Version 4.0 and maybe older), I would like to make these recommendations to the TextPad staff to simplify breakpoints even further:
Optional feature requests I am making to the TextPad people:
- TextPad API Call: Clear all bookmarks(used as breakpoints)
- TextPad API Call: Highlight bookmark(breakpoint) on a specified line
- TextPad API Call: Return TRUE if specified line is highlighted with a bookmark
- TextPad API Call: Return a comma-delimited string of numbers listing all the line numbers of all bookmarked lines for the current document.
- TextPad API Call: Accepts a comma-delimited string of numbers listing all the line numbers and set bookmarks on all of these lines without moving cursor or scrolling the document.
- TextPad API Call: Gets the current cursor position
- TextPad API Call: Gets the currently-displayed document
- These are the main API call additions I'd like the TextPad people to make, the others (DDE) works perfectly.

(Doesn't matter what API method, SendMessage / PostMessage calls or DDE calls. Can accomodate either. DDE is a pain in some ways, but I am familiar with DDE.)

(Note: While preferable, these aren't critical to make TextPad an IDE, because I've successfully been able to do ALL the above using message-monitoring loops as well as DDE cursor-positioning calls as well as keypress automation of TextPad to send a simulated Ctrl+F2 via virtual keypress using Windows API, but there's about 1 to 2 seconds worth of screen mayhem to automatically highlight multiple bookmarks on specific lines of a specific document, and the document scrolls like mad, as it bookmarks subsequent lines of bookmarks later on in the same document. I'd like to do this without any on-screen mayhem or simulated-keypress automation -- i.e. as an example, set bookmarks on line numbers 5, 7, 76, 80, 192, 193, 250, 287, etc -- in the background without moving the cursor or scrolling the document.)
Thanks,
Mark Rejhon
www.marky.com
(to contact me, please use the spamproof link at bottom of any page on my website)
Mark Rejhon
Posts: 11
Joined: Sat Aug 07, 2004 6:36 pm
Location: Ottawa, Ontario, Canada
Contact:

Post by Mark Rejhon »

Update...

Although I'm originally creating this utility for my language mainly. I'm also considering selling the source code to this utility to interested parties/businesses who needs to make TextPad a true IDE, especially scripting languages developed from scratch. Opinions?

Please remember, no modifications are made to TextPad, it's just like writing a third party automation utility that automates an app, such as Excel or Word or Explorer. No different in concept, so it's fully legal to my understanding. But I understand not all programmers have the skill to write a system-hook/automation utility like I have, it's very complicated programming for some people, and might prefer to buy a copy of source code from me for their own products...

Of course, anybody who wants to use TextPad should buy licenses from the TextPad people themselves...

Any opinions from the TextPad people too?
Thanks,
Mark Rejhon
www.marky.com
(to contact me, please use the spamproof link at bottom of any page on my website)
User avatar
delley
Posts: 13
Joined: Mon Jan 12, 2004 10:26 am

What about...?

Post by delley »

Hi Mark,

Excellent work and great research :D :D :D

From your description it looks like your tests has been done with a scripting language. How does all this looks if you want the same functionality with compiled languages :?:

Regards,

delley
Now - suddenly everybody is a comedian!?!
Mark Rejhon
Posts: 11
Joined: Sat Aug 07, 2004 6:36 pm
Location: Ottawa, Ontario, Canada
Contact:

Post by Mark Rejhon »

Has any other third party developers used my technique to turn TextPad into an IDE?
Thanks,
Mark Rejhon
www.marky.com
(to contact me, please use the spamproof link at bottom of any page on my website)
Post Reply