Kip

SciLexer UDF

103 posts in this topic

#1 ·  Posted (edited)

Title says enough (For those who don't know, scilexer is an editing control, like the one SciTE uses)

It now supports multiple editors, and allows you to write your own lexer.

Functions:

Func Sci_CreateEditor($Hwnd, $X,$Y,$W,$H)

Func Sci_DelLines($Sci)

Func Sci_AddLines($Sci, $Text,$Line)

Func Sci_GetLines($Sci)

Func Sci_GetLine($Sci, $Line)

Func Sci_InsertText($Sci, $Pos, $Text)

Func Sci_GetCurrentPos($Sci)

Func Sci_SetCurrentPos($Sci, $Char)

Func Sci_GetLineFromPos($Sci, $Pos)

Func Sci_GetLineStartPos($Sci, $Line)

Func Sci_SetAnchor($Sci, $iPos)

Func Sci_SetCurrentPosEx($Sci, $iPos)

Func Sci_SetZoom($Sci, $Zoom)

Func Sci_GetZoom($Sci)

Func Sci_VisibleFirst($Sci)

Func Sci_VisibleLines($Sci)

Func Sci_GetLineEndPos($Sci, $Line)

Func Sci_GetLineLenght($Sci, $Line)

Func Sci_GetLineCount($Sci)

Func Sci_SetCurrentLine($Sci, $Line)

Func Sci_GetCurrentLine($Sci)

Func Sci_GetChar($Sci, $Pos)

Func Sci_GetCurrentWord($Sci)

Func Sci_SetSelection($Sci, $BeginChar, $EndChar)

Func Sci_GetSelection($Sci)

Func Sci_SetSelectionColor($Sci, $Color, $State=True)

Func Sci_SetSelectionBkColor($Sci, $Color, $State=True)

Func Sci_SetSelectionAlpha($Sci, $Trans)

Func Sci_ReplaceSel($Sci, $sText)

Func Sci_SelectAll($Sci)

Func Sci_Cut($Sci)

Func Sci_Copy($Sci)

Func Sci_Paste($Sci)

Func Sci_StyleApply($Sci, $iStyle, $iStartPos, $iLenght)

Func Sci_StyleSet($Sci, $iStyle, $iColor=-1, $iBkColor=-1, $iBold=-1, $iItalic=-1, $iUnderline=-1, $sFont=-1, $iFontSize=-1)

Func Sci_StyleClearAll($Sci)

Func Sci_GetStyleAt($Sci, $iPos)

Func Sci_SetLexer($Sci, $iLexer)

Func Sci_GetLexer($Sci)

Sci_CalltipShow($Sci, $iPos, $sText)

Sci_CalltipActive($Sci)

Sci_CalltipCancel($Sci)

Sci_CalltipHighlight($Sci, $iStartPos, $iEndPos)

Sci_CalltipPos($Sci)

Sci_CallTipSetHltColor($Sci, $iColor)

Sci_CallTipSetColor($Sci, $iColor)

Sci_CallTipSetBkColor($Sci, $iColor)

Sci_AutoCompleteActive($Sci)

Sci_AutoCompleteCancel($Sci)

Sci_AutoCompleteShow($Sci, $iLen, $sWords)

Sci_LineWrapSetMode($Sci, $iMode)

Sci_LineWrapSetIndent($Sci, $iMode)

Sci_LineWrapSetIndentLocation($Sci, $iLocation)

Sci_SetSavePoint($Sci)

Sci_GetModify($Sci)

Sci_SelectionSetBkColor($Sci, $iColor, $iUse=True)

Sci_SelectionSetColor($Sci, $iColor, $iUse=True)

Sci_SelectionSetAlpha($Sci, $iAlpha)

Sci_SelectionGetAlpha($Sci)

Sci_CaretSetColor($Sci, $iColor)

Sci_CaretGetColor($Sci)

Sci_CaretSetWidth($Sci, $iWidth)

Sci_CaretGetWidth($Sci)

Sci_FoldingShowLines($Sci, $iStart, $iEnd)

Sci_FoldingHideLines($Sci, $iStart, $iEnd)

Sci_FoldingToggleFold($Sci, $iLine)

Kip :)

Old version (where AutoIt is the standard language)

SciLexer.zip

New version (which allows you to create your own lexer):

_SciLexer.zip

I recommend to use the new version

Edit: AutoIt now isn't the standard language anymore

Edited by Kip

Share this post


Link to post
Share on other sites



I realize this is somewhat of an old topic but anyone know how i could get the line count?


[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Share this post


Link to post
Share on other sites

I realize this is somewhat of an old topic but anyone know how i could get the line count?

Read it to an array and then check array[0] or Ubound(Array)-1

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Read it to an array and then check array[0] or Ubound(Array)-1

How about resizing so i can resize my window and it resizes with it i have never played with resizing.

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Share this post


Link to post
Share on other sites

Great work.

A great function to add would be the syntax coloring.


[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Added 9 new functions and an example, see first post for file and info.

Edited by kip

Share this post


Link to post
Share on other sites

can someone elaborate on what this is? and what it is used for?

I googled and it appears it's part of many software packages, but is till cant seem to figure out what it does and what this could be used for.

thanks

Share this post


Link to post
Share on other sites

Wow, this is really cool!

Question does the get current selecetion return a string or raw text?


My Scripts,[topic="65986"]AI Example[/topic] ,Capable of Emotion!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

can someone elaborate on what this is? and what it is used for?

Its a rich-text editing control, like the one that SciTE uses.

Question does the get current selecetion return a string or raw text?

it returns the first pos and the last pos of the selection.

You can use GetLines() and StringMid() to get the text.

$Sel = Sci_GetSelection()
$Text = Sci_GetLines()
$SelectedText = StringMid($Text,$Sel[0]+1,$Sel[1]-$Sel[0])
MsgBox(0,"blabla", $SelectedText)
Edited by kip

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Bumping because this is such a great UDF, and because I have an issue :)

I began writing a small text editor with syntax highlighting. Here's a little teaser:

Clicky

But I noticed that your Sci_Getlines function is extremely slow on even small files. I tried opening a 180 line script I wrote using Sci_AddLines, and worked in a few milliseconds. Now, trying to read this data with Sci_GetLines took about 25 seconds. Is this a known limitation with the SciLexer? SciTe doesn't seem to do this.

EDIT: I also updated your syntax files with those from the latest release. I can attach that if you want, someone might want it.

Edited by KentonBomb

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Now, trying to read this data with Sci_GetLines took about 25 seconds.

I guess it's just you, it takes less than a blink with my eye to get all the lines. :)

EDIT: I also updated your syntax files with those from the latest release. I can attach that if you want, someone might want it.

If you want to, it would be great :)

Edit: can you show me how/when you use GetLines() ?

Edited by Kip

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Here's an excerpt from the exit function:

If $sCurrentFile = "" Then
    Exit
Else
    $sCurrentData = Sci_GetLines()
    If FileRead($sCurrentFile) <> $sCurrentData Then
        Switch MsgBox($MB_YESNOCANCEL, "Would you like to save?", "Would you like to save your work?")
            Case $IDYes
                FileWrite(FileSaveDialog("Save File", @WorkingDir, "Autoit Scripts (*.au3)"), $sCurrentData)
                Exit
            Case $IDNo
                Exit
        EndSwitch
    Else
        Exit
    EndIf
EndIf

Obviously you cannot run this example without the GUI, but you see the point.

EDIT: Defs for 3.2.12.0: http://ktech.heliohost.org/Defs_3212.zip

EDIT2: Hmm. Those drastic times were a result of a bad CPU-Hogging loop I had going on. A 500 Line script does still take at least 8 seconds to read with Sci_GetLines though. It's not nearly as bad, so I can live with it.

Edited by KentonBomb

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

It should be faster, if you use

$sText = BinaryToString(DllStructGetData($sBuf, 1))

instead of

;   For $i = 1 To $iLen - 1
;       $sText &= Chr(DllStructGetData($sBuf, 1, $i))
;   Next

And in Func Sci_AddLines($Text,$Line) i would use

. $LineLenght = StringLen($Text)

instead of

. $LineLenght = StringSplit($Text,"")

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

I added 21 new functions, multiple controls support, and autocomplete for variables (i'm sure you can add autocomplete for functions by yourself :) )

Share this post


Link to post
Share on other sites

Hey Kip! Nice UDF!

I have a question for you.

How do I go about adding an embedded SciTE into a Tab control? It all runs fine but nothing shows up.

And after messing with it I realized I had to supply it the handle to the window. Is there anything I can do to make this work inside the tab not below the tab? ;)

Thanks

Share this post


Link to post
Share on other sites

Create a small tab control above it. So you only see the tab buttons, not the tab pages. Then check if a tab is pressed, if so: show scilexer, else: hide it

Share this post


Link to post
Share on other sites

Added 9 new functions! they all are style functions.

- Sci_StyleApply()

- Sci_StyleSet()

- Sci_StyleClearAll()

- Sci_GetStyleAt()

- Sci_SetLexer()

- Sci_GetLexer()

AutoIt isn't the default language anymore, so it's time to make something on your own.

You can use Sci_SetLexer() to switch back to AutoIt though.

Share this post


Link to post
Share on other sites

You should rename your functions to normal UDf Style.

the public Functions _Sci_ or _GUICtrlSciLexer_

and the internal funcs with like the standard funcs, but with double underscore at the beginning :) So there will be less problems if those functions are used in other UDFs


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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