IDE Tool to insert text into your source code

Working on new editor enhancements?
User avatar
Blue
Addict
Addict
Posts: 880
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

IDE Tool to insert text into your source code

Post by Blue »

The following piece of code makes it possible to insert some fixed expression
in your source code at the current cursor location :

Code: Select all

; Compile the following bit of code as Unicode
; and add the resulting exe to your IDE Tools by 
; (1) providing the path to your exe
; (2) giving your tool a descriptive name
; (3) assigning it a KBD shortcut (for added convenience)

Procedure MakeScintillaText(text.s)
  Static sciText.s
  CompilerIf #PB_Compiler_Unicode
    sciText = Space(StringByteLength(text, #PB_UTF8))
    PokeS(@sciText, text, -1, #PB_UTF8)
  CompilerElse
    sciText = text
  CompilerEndIf
  ProcedureReturn @sciText
EndProcedure

textBuffer = MakeScintillaText("Let's try this...")
scintilla = Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
SendMessage_(scintilla, #EM_REPLACESEL, 0, textBuffer)
Remember to replace the demo text with your own !

I use it with <Control>+i, for instance, to quickly insert the forever recurring "#PB_" constant identifier,
and to insert standardized identifier lines at the beginning of my source code files.

It does save a lot of finger work.

The Procedure itself comes straight from the Help File (topic : ScintillaGadget()),
while the rest is from a piece of code offered by Netmaestro (Look here).

Using the code Netmaestro provided, i could only insert the first character of any text.
So, to insert a 5 characters word, SendMessage_() had to be called 5 times with 5 different characters...
Using the above, everything gets insrted in one shot.

At this writing, this code works nicely in PB 5.31 (x86) on a Windows 8.1 x64 system.
I haven't tried it on other configurations.

If you come up with interesting improvements/modifications, please share.
In particular, it would be great if one of the propeller heads around here
helped provide a scrolling list for selecting among a choice of
expressions, à la PureBasic IDE's auto-complete feature.

Enjoy.

BTW: (off topic, but...) if anyone knows how to get the URL to a specific message in a topic page, i'd really appreciate being told how to do it...
Last edited by Blue on Sun Mar 15, 2015 5:30 pm, edited 2 times in total.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Inserting text in your source code

Post by Vera »

Blue wrote:BTW: (off topic, but...) if anyone knows how to get the URL to a specific message in a topic page, i'd really appreciate being told how to do it...
The page-icon in a posting-title contains its specific posting-address :arrow: Image Posted: 06.03.15 12h38

happy sharing :-)
User avatar
Blue
Addict
Addict
Posts: 880
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Inserting text in your source code

Post by Blue »

Vera wrote:[...] The page-icon in a posting-title contains its specific posting-address
Ummm... Thank you for the tip, Vera... but what is the page-icon ??? :oops:
I've dragged my mouse all over the current page, but i never saw the specific post number appear anywhere.
Maybe i just need stronger glasses... :(

OK. Never mind. I think i finally got it. :P
You were referring to the tiny icon at the extreme right of the message header, just before the 'Posted' date, correct ? :shock:
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Inserting text in your source code

Post by Vera »

Blue wrote:I think i finally got it. :P
You were referring to the tiny icon at the extreme right of the message header, just before the 'Posted' date, correct ? :shock:
I'm glad you did :D
and yes. I'd thought that my 'reconstruction' would have already been selfexplaning enough, but I can comprehend that this single word 'page' must have been missleading to focus on the full thread-page, instead on that increadibly tiny icImagen.
User avatar
Blue
Addict
Addict
Posts: 880
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Inserting text in your source code

Post by Blue »

Vera wrote:[...]I'd thought that my 'reconstruction' would have already been selfexplaning enough
Oh, Vera, you manifestly don't know who you're dealing with here ... :mrgreen:
But since i've got it all figured out now, i can see how brilliant and self-explanatory your artful reconstruction was. :!: :!: :!:
I really don't know how i could have missed it the first time around. I guess it was just too clever.

That tells you a lot about the perils of human communication.

Thanks a lot for your illustrated contribution.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
Post Reply