Sign in to follow this  
Followers 0
mattw112

SciTe Editor Formatting

14 posts in this topic

Does anyone have any code or idea on how I would create a script that I could run that would go through the lines of code shown in the SciTe Editor window and if they start with "Func" then it collapses the line?

Basically I can do the Alt+V+A to collapse or uncollapse everything, but really I just want the functions collapsed.

Thanks,

Terry

PS - From looking at the AutoIT info tool the main window with the code just says:

>>>> Control <<<<

Class: Scintilla

Instance: 1

ClassnameNN: Scintilla1

Name:

Advanced (Class): [CLASS:Scintilla; INSTANCE:1]

Not sure how to interact with that.

Thanks,

Terry

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You could use #Region and #EndRegion before and after each functions. That will allow you to collapse the code. See Next Post.

#Region
Func _HelloWorld()
    MsgBox(0, "", "Hello World")
EndFunc
#EndRegion
Edited by czardas

Share this post


Link to post
Share on other sites

Oops, I just realized that functions can be collapsed anyway. :blink:

However, if you group all your functions into one long region. You can collapse that.

Share this post


Link to post
Share on other sites

Oops, I just realized that functions can be collapsed anyway. :blink:

However, if you group all your functions into one long region. You can collapse that.

Yes I know that's part of the problem. I want to be able to work on the functions one at a time, and want to be able to easily collapse all functions to begin with, because every time I build then it uncollapses regions, and the functions inside...

Anyway just want to be able to interact with the code window in SCiTE and read one line at a time. If I find Func to begin with I'll Alt+V+C with collapses or uncollapses that particular line....

Thanks,

Terry

Share this post


Link to post
Share on other sites

Hmm, I see what you mean. You could compile copies of the original for testing. That way the original should not be affected. Otherwise I don't know.

Share this post


Link to post
Share on other sites

So anyone know how to interact with the control

>>>> Control <<<<

Class: Scintilla

Instance: 1

ClassnameNN: Scintilla1

Name:

Advanced (Class): [CLASS:Scintilla; INSTANCE:1]

Thanks,

Terry

Share this post


Link to post
Share on other sites

The only thing I can think of and could be checked is a script using the Scitilla Director interface or a LUA script, but don't have time at the moment to investigate in detail. Best bet at the moment is a LUA script.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I'm sorry, before I posted I searched the forum on SciTe and didn't get much, but just tried searching on the control name and got tons of examples. including one for Jos that looks pretty good to start...

I'll try more, but I think these examples will get me there.

Terry

Share this post


Link to post
Share on other sites

Offtopic, Notepad++ has where you can collapse levels. I was able to do alt3 on my "style" of coding and just show functions.

Share this post


Link to post
Share on other sites

Offtopic, Notepad++ has where you can collapse levels. I was able to do alt3 on my "style" of coding and just show functions.

It is using the same Scintilla engine, for which I coded AutoIt3 lexer, so Notepad++ code folding is the same as SciTE. :blink:

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

So I've almost got it working now...

Only problem left is how do I tell if a line in the editor is folded already or not?

Is there some control command I can use to get this?

Terry

PS - a couple other things I've worked around but would be good to know is:

Is there a command to tell the editor window to go to a certain line number directly? Currently I'm just doing ctrl G.

Seems like some of the controlsend's only work if the window is activated... anyway around that?

Is there a way to get the text from the line where the cursor is at in the editor? Currently I'm just reading the .Au3 file figuring out what line number it is then going to the editor and going down to that line. Would be easier to just read the editor directly.

Edited by mattw112

Share this post


Link to post
Share on other sites

Maybe you could first tell me how you are coding it so I understand the approach? :blink:

Pretty clugy actually... just threw together stuff below. Works for what I'm trying to do except the being able to tell if it is already Collapsed or not.

$Count = "0"

; Get the script name from the title bar, that will ensure get the current tab's script
If WinExists("[CLASS:SciTEWindow]") Then
    $Title = WinGetTitle("[CLASS:SciTEWindow]")
    $pos = StringInStr($Title, ".au3")
    $Title = StringLeft($Title, $pos + 3)

    ; Seems like the window has to be activated for the ALTDOWN\UP, etc to work...
    WinActivate("[CLASS:SciTEWindow]")

Else
    MsgBox(16, "Error", "No SciTE Window open")
    Exit(1)
EndIf

$file = FileOpen($Title, 0)

While 1

    $Count = $Count + 1

    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringLeft($line, 4) = "Func" Then

        ; Go to line #
        ControlSend("[CLASS:SciTEWindow]", "", "Scintilla1", "^g")
        WinWait("Go To")
        WinSetState("Go To", "", @SW_HIDE)
        ControlSend("Go To", "", "Edit1", $Count)
        ControlClick("Go To", "", "Button1")
        Sleep(500)

        ; Send commands to collapse
        ; Assumes Func not collapsed.  At some point would need to do a check to see if it already is and if not do so.
        ControlSend("[CLASS:SciTEWindow]", "", "Scintilla1", "{ALTDOWN}")
        ControlSend("[CLASS:SciTEWindow]", "", "Scintilla1", "vc")
        ControlSend("[CLASS:SciTEWindow]", "", "Scintilla1", "{ALTUP}")

    EndIf

Wend

FileClose($file)

Exit(0)

#cs

; Test if already collapsed

#ce

Func _Test1()
    ; This should be collapsed by the code
EndFunc


Func _Test2()
    ; This should be collapsed by the code
EndFunc

Terry

Share this post


Link to post
Share on other sites

Well I submitted this like a week ago...

Any ideas on being able to tell if the line is collapsed or not already?

Thanks,

Terry

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0