Can I create a FOLD on a selected bit of code?

Just starting out? Need help? Post your questions and find answers here.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Can I create a FOLD on a selected bit of code?

Post by AMpos »

Hi!

Can I create a fold on a selected piece of code. I mean, I select a few lines with the mouse, click on a button/menu and insert ;{ at start and ;} at the end:

Code: Select all

line 1
line 2
line 3
line 4
After selecting LINE 2 & LINE 3, choose "create fold":

Code: Select all

line 1
;{
line 2
line 3
;}
line 4
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Can I create a FOLD on a selected bit of code?

Post by infratec »

Sorry, but I cant not read where you need this.

IDE, EditorGadget(), StringGadget(), ScintillaGadget() ...

From what you are talking?

If you mean the IDE, you can create a tool which do this.
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: Can I create a FOLD on a selected bit of code?

Post by BarryG »

He means the IDE, like we can select a group of lines to comment with Ctrl+B. He wants something like that but to insert fold marks at the start and end of the selected code block. It can't be done natively and would need a tool, as you said. Or he could post it in "Feature Requests" maybe.
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Can I create a FOLD on a selected bit of code?

Post by infratec »

Code: Select all

EnableExplicit

#SetCursor = #True

Define IDEGadgetID.i, SavedClipboardText$, IDEText$

CompilerIf #SetCursor
  Define StartPos.l
CompilerEndIf


IDEGadgetID = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
If IDEGadgetID
  CompilerIf #SetCursor
    StartPos = SendMessage_(IDEGadgetID, #SCI_GETSELECTIONSTART, #Null, #Null)
  CompilerEndIf
  SavedClipboardText$ = GetClipboardText()
  SetClipboardText("")
  SendMessage_(IDEGadgetID, #SCI_COPY, #Null, #Null)
  IDEText$ = GetClipboardText()
  If IDEText$ <> ""
    SetClipboardText(";{ " + #LF$ + IDEText$ + #LF$ + ";}")
    SendMessage_(IDEGadgetID, #SCI_PASTE, #Null, #Null)
    CompilerIf #SetCursor
      StartPos + 3
      SendMessage_(IDEGadgetID, #SCI_GOTOPOS, StartPos, #Null)
    CompilerEndIf
  EndIf
  SetClipboardText(SavedClipboardText$)
EndIf
Compile it to an Exe and add it to the Tools.

I'm not 100% sure about the #LF$ maybe it should be a #CRLF$, but it looks that it works.
Last edited by infratec on Fri Jul 24, 2020 8:19 am, edited 4 times in total.
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Can I create a FOLD on a selected bit of code?

Post by NicTheQuick »

You can create a Feature Request on Github: https://github.com/fantaisie-software/purebasic/issues
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Can I create a FOLD on a selected bit of code?

Post by AMpos »

infratec wrote:

Code: Select all

EnableExplicit


Define IDEGadgetID.i, SavedClipboardText$, IDEText$

IDEGadgetID = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
If IDEGadgetID
  SavedClipboardText$ = GetClipboardText()
  SetClipboardText("")
  SendMessage_(IDEGadgetID, #SCI_COPY, #Null, #Null)
  IDEText$ = GetClipboardText()
  If IDEText$ <> ""
    SetClipboardText(";{" + #LF$ + IDEText$ + #LF$ + ";}")
    SendMessage_(IDEGadgetID, #SCI_PASTE, #Null, #Null)
  EndIf
  SetClipboardText(SavedClipboardText$)
EndIf
Compile it to an Exe and add it to the Tools.

I'm not 100% sure about the #LF$ maybe it should be a #CRLF$, but it looks that it works.
It works at first try! Love you! :wink:
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Can I create a FOLD on a selected bit of code?

Post by AMpos »

Just asking... can it be modified to place the cursor just after the ";{" :mrgreen:
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Can I create a FOLD on a selected bit of code?

Post by infratec »

Extended the listing above.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Can I create a FOLD on a selected bit of code?

Post by AMpos »

infratec wrote:Extended the listing above.
Thanks dude!
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Can I create a FOLD on a selected bit of code?

Post by infratec »

Ahhh, you want to extend the first line with an additional comment after 'insert folding'.
I corrected the listing above (added a space and + 4 is changed to + 3)
Post Reply