Paste as comment

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
sys64802
Enthusiast
Enthusiast
Posts: 105
Joined: Sat Sep 12, 2015 6:55 pm

Paste as comment

Post by sys64802 »

Beyond Edit->Paste would be nice to have Edit->Paste as comment

Often I need to paste code from other languages, or text I want add as a comment and I have to use a temporary external editor to paste, add ";", and then copy+paste in the IDE.

Else case correction wrecks havoc (as can be seen in most codes here in the forum, where innocent English words are capitalized).

I know I could implement it by myself by writing a IDE tool, but the code to do it it's practically already there in the PB IDE.

Thanks.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Paste as comment

Post by Andre »

+1
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Paste as comment

Post by IdeasVacuum »

+1 would be good
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Paste as comment

Post by Tenaja »

Although I am also +1 on this, I usually use the comment creator plugin someone contributed. While not as instant, it gives the opportunity to reformat without styling added.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Paste as comment

Post by davido »

+1
DE AA EB
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Paste as comment

Post by Little John »

That would be helpful.
+1
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Paste as comment

Post by Kukulkan »

+1

That would be helpful, indeed.
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Paste as comment

Post by Michael Vogel »

As you mentioned, it shouldn't be a great deal to create an IDE tool, just send a ctrl+v event after changing the clipboard as you like it - which gives you total flexibility.

Code: Select all

; Tool "ClipInsert"		Written by Michael Vogel

; Command Line:		%COMPILEFILE\..\Catalogs\Tool ClipComment.exe
; Working Directory:	%COMPILEFILE\..
; Name:				Insert Clipboard as Comment...
; Run Hidden

#Header=";"+#TAB$
SetClipboardText(#Header+ReplaceString(GetClipboardText(),#CRLF$,#CRLF$+#Header))

keybd_event_(#VK_CONTROL,1,0,0)
keybd_event_(#VK_V,1,0,0)
keybd_event_(#VK_V,1,2,0)
keybd_event_(#VK_CONTROL,1,2,0)

IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Paste as comment

Post by IdeasVacuum »

..... Very nice Michael. 8)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Paste as comment

Post by kenmo »

+1

I like this idea! I think I will add it to my own IDE tool and link it to Ctrl-Shift-V.

Michael already posted a working snippet, here is a slightly different one (it uses #SCI_PASTE directly to the Scintilla gadget instead of virtual keypresses, and it restores the original clipboard)

Code: Select all

Prefix.s = "; "
SCID = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
Orig.s = GetClipboardText()
If (SCID And Orig)
  Mod.s = ReplaceString(Orig, #CRLF$, #LF$)
  Mod = Prefix + ReplaceString(Mod, #LF$, #LF$ + Prefix) + #LF$
  SetClipboardText(Mod)
  SendMessage_(SCID, #SCI_PASTE, 0, 0)
  SetClipboardText(Orig)
EndIf
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Paste as comment

Post by Michael Vogel »

Okay, one more iteration (hold 'ctrl' to change behaviour)...

Code: Select all

; Tool "ClipInsert"		Written by Michael Vogel and Kenmo

; Command Line:		%COMPILEFILE\..\Catalogs\Tool ClipComment.exe
; Working Directory:	%COMPILEFILE\..
; Name:				Insert Clipboard as Comment...
; Run Hidden

Define.s in,out

#Scintilla=	1
#Prefix=		";"+#TAB$

CompilerIf #Scintilla
	Ok=Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
CompilerElse
	Ok=#True
CompilerEndIf

in=GetClipboardText()

If in And Ok
	
	out=ReplaceString(in,#CRLF$,#CR$)
	out=#Prefix + ReplaceString(out,#CR$,#CR$ + #Prefix)
	If Right(out,1)<>#CR$
		out+#CR$
	EndIf
	If GetKeyState_(#VK_CONTROL)&128
		out=ReplaceString(out,#CR$+#Prefix+#CR$,#CR$+#CR$)
	EndIf

	SetClipboardText(out)
	
	CompilerIf #Scintilla
		SendMessage_(Ok,#SCI_PASTE,0,0)
	CompilerElse
		keybd_event_(#VK_CONTROL,1,0,0)
		keybd_event_(#VK_V,1,0,0)
		keybd_event_(#VK_V,1,2,0)
		keybd_event_(#VK_CONTROL,1,2,0)
	CompilerEndIf
	
	SetClipboardText(in)
	
EndIf
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Paste as comment

Post by Lunasole »

Nice.
I've used Kenmo variant (additionally added #LFCR$ to replace), other works fine too
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Paste as comment

Post by kenmo »

Implemented in PB 5.72 IDE, so we don't need tools which disrupt the clipboard anymore :)
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Paste as comment

Post by Demivec »

kenmo wrote:Implemented in PB 5.72 IDE, so we don't need tools which disrupt the clipboard anymore :)
This was already implemented as a right- click option in the IDE previous to it going open source.
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: Paste as comment

Post by leonhardt »

select all,Ctlr+B . doesn't work?
poor English...

PureBasic & Delphi & VBA
Post Reply