Page 1 of 1

IDE Tool to insert text into your source code

Posted: Fri Mar 06, 2015 12:38 pm
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...

Re: Inserting text in your source code

Posted: Fri Mar 06, 2015 4:12 pm
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 :-)

Re: Inserting text in your source code

Posted: Sat Mar 07, 2015 2:36 pm
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:

Re: Inserting text in your source code

Posted: Sat Mar 07, 2015 9:41 pm
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.

Re: Inserting text in your source code

Posted: Sat Mar 07, 2015 11:13 pm
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.