Scintilla: auto-indent: how to?

Just starting out? Need help? Post your questions and find answers here.
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Scintilla: auto-indent: how to?

Post by morosh »

Hello:
I'm searching for auto-indent feature for Scintilla, with no luck.
did someone developed that and like to share?

Thanks in advance
PureBasic: Surprisingly simple, diabolically powerful
TassyJim
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: Scintilla: auto-indent: how to?

Post by TassyJim »

My method which is unlikely to be the "correct" way is:
I intercept the CR key and do a number if things when the line ends.
Because the CR was intercepted, the first thing is to insert the end-of-line character(s)
Then I copy the line indentation from the last line to the new line.
Look in the scintilla help for #SCI_GETLINEINDENTATION and #SCI_SETLINEINDENTATION.
You might want to work out if the new line needs a different indentation based on the text of the previous line.

It works for me...
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: Scintilla: auto-indent: how to?

Post by morosh »

Thank you, I'll try.

Meanwhile, I still searching for a readymade solution
PureBasic: Surprisingly simple, diabolically powerful
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: Scintilla: auto-indent: how to?

Post by firace »

Perhaps you can take a look at the PB IDE source code, which uses Scintilla:

https://www.purebasic.fr/english/viewtopic.php?t=74151


(Procedure UpdateIndent and Procedure AutoIndent)
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Scintilla: auto-indent: how to?

Post by Tenaja »

morosh wrote: Sun Jul 28, 2024 7:31 am Hello:
I'm searching for auto-indent feature for Scintilla, with no luck.
did someone developed that and like to share?

Thanks in advance
Look for GoScintilla on the forum. It's a full featured library that takes care of almost all of the regularly used features of an IDE, including this. At the least, you can copy the procs needed.
User avatar
skywalk
Addict
Addict
Posts: 4219
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Scintilla: auto-indent: how to?

Post by skywalk »

I was considering migrating from rich editor to scintilla for easier syntax highlighting and indenting.
I started to browse the IDE code but globals are in another area and it is slightly difficult to follow.
Does GoScintilla support syntax highlighting?
I read Lexilla is now a separate lib.
Does anyone have code snippet calling the lexer directly?
Is it less or more work to recreate the lexer commands for a single language?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: Scintilla: auto-indent: how to?

Post by morosh »

Thank you all!!!
yes GoScintilla is really excellent, finally my callback looks like that (if anyone is also looking for, like me):

Code: Select all

Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
  Protected nPos, startLine, level
  Select *scinotify\nmhdr\code
    Case #SCN_CHARADDED
      If  *scinotify\ch=10
        nPos = ScintillaSendMessage(Gadget, #SCI_GETCURRENTPOS)
        startLine = ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, nPos)-1
        level = ScintillaSendMessage(Gadget, #SCI_GETLINEINDENTATION, startLine)
        If level > 0
          startLine+1
          ScintillaSendMessage(Gadget, #SCI_SETLINEINDENTATION, startLine, level)
          nPos =  ScintillaSendMessage(Gadget, #SCI_GETLINEINDENTPOSITION, startLine)
          ScintillaSendMessage(Gadget, #SCI_GOTOPOS, nPos)
        EndIf        
      EndIf
    Case #SCN_STYLENEEDED
      Highlight(Gadget, *scinotify\position)
  EndSelect 
EndProcedure
PureBasic: Surprisingly simple, diabolically powerful
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Scintilla: auto-indent: how to?

Post by Tenaja »

Does GoScintilla support syntax highlighting?
gosci is a full featured customizable lexer that supports almost everything.
User avatar
skywalk
Addict
Addict
Posts: 4219
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Scintilla: auto-indent: how to?

Post by skywalk »

Where is the latest gosci lib/module?
I found a module from 2019.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Scintilla: auto-indent: how to?

Post by Tenaja »

skywalk wrote: Fri Aug 02, 2024 4:47 pm Where is the latest gosci lib/module?
I found a module from 2019.
That module is probably the latest. I have not been using it lately, so I have not updated it myself. With srod being inactive since 2020, he has not been updating it. However, in 2017, he posted:
current version of GoScintilla (2.7) seems to work fine with PB 5.51 x86
Any updates that are required should be minimal. It is an excellent, thorough, and consistent library, and would be worth your time if you want to do anything more than one or two features. The examples that he provided were also quite helpful, and well rounded.
User avatar
skywalk
Addict
Addict
Posts: 4219
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Scintilla: auto-indent: how to?

Post by skywalk »

I found it here: v301
Yes, it is an excellent library. I was writing too much code already available in these fine libs.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
TassyJim
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: Scintilla: auto-indent: how to?

Post by TassyJim »

GoScintilla works well with PB6.11 x64. Windows and Linux.
There are a few places where .l needs changing to .i
I also had to change the size allocated to some string buffers at some stage. My notes are not very informative.

My main project uses a mixture of goScintilla and direct ScintillaSendMessage calls.
User avatar
skywalk
Addict
Addict
Posts: 4219
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Scintilla: auto-indent: how to?

Post by skywalk »

Dang it!
I'm crashing the calltip demo's when compiling threadsafe.
Without creating a thread!
Meaning, I'm just running the example code with/without threadsafe.
Just hitting backspace or enter?

And the lib does not support UTF8 characters?

I might have to go back and rewrite just what I need. :oops:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply