Scintilla class wrapper for AHK v2
Go to the Scintilla site to get the DLL. Here is the download page for SciTE.
Direct Links:
Pick your desired 32-bit or 64-bit version for download. Unzip and copy over the Scintilla.dll
from the unzipped folder into the same folder as the script. You can of course place the DLL anywhere, but make sure you modify the class lib in Static __New()
to point to the proper DLL location.
On to the next phase:
I've started to dabble in C. I wrote a DLL to handle the styling routine (source is of course included - CustomLexer.c). This includes 3 functions.
"string"
, 'string'
, ; line comment
, /* block comment */
, numbers, hex numbers, punctuation (operators / separators), braces.The main method that uses these is: wm_messages(wParam, lParam, msg, hwnd)
.
There are method wrappers of the same function names that employ these DLL functions.
I've used the following file as a test (thanks to marius - aka robodesign). This script is 2.16 MB in size and loads with syntax highlighting in currently just over a second (1.078 - 1.218 secs on my machine).
Test document link (this doc is included as test-script.ahk
):
https://github.com/marius-sucan/Quick-Picto-Viewer/blob/master/quick-picto-viewer.ahk
NOTE: If you use LayoutCaching, you may get occasional slower load times (up to 14 seconds on test-script.ahk
according to my tests). It's a bit random, but this never seems to happen with LayoutCache disabled. LayoutCache is mostly only useful if you need smoother performance when resizing the window (ie. not maximized). You will still get smooth scrolling with LayoutCache disabled.
Making the documentation will be a lengthy work in progress...
For now all I can give is a general outline and some guidelines:
All numerical IDs are zero-based. So position numbers, line numbers, column numbers, margin numbers, style numbers, selection numbers, etc., start at zero.
I tried to keep all like categories of methods and properties together as they are listed on the Scintilla Documentation site, but this is not always the case. Generally I'm just trying to keep concepts in logical categories (sub classes). This is a bit of a process as I discover other functions, some of which serve a better purpose in a different category than originally listed in the Scintilla Docs.
Not all Scintilla functions will make it into this library. Basically, functions that appear to duplicate another function's result with little or no benefit won't be added, unless there is a good reason, in which case it may get a different name to more appropriately describe what it is best used for.
I will always append a comment for a property or method that makes use of a particular SCI_...
message name so it should be easy to see what my script is doing while refrencing the Scintilla documentation.
Below I will outline major features or major parts of the script class structure.
g := Gui()
ctl := g.AddScintilla(...)
ctl.callabck := my_func
my_func(ctl, scn) {
...
}
ctl
is the Gui Control object, the Scintilla control.
scn
is the SCNotification struct as a sub-class.
scn
Members:
hwnd\ id\ wmmsg\ wmmsg_txt <-- added text name of wm_notify msg\ pos\ ch\ mod\ modType\ text\ textPtr\ length\ linesAdded message\ wParam\ lParam\ line\ foldLevelNow\ foldLevelPrev\ margin\ listType\ x\ y\ annotationLinesAdded\ updated\ listCompletionMethod\ characterSource
ctl.cust.{category}.{property}
Properties are as follows unless indicated otherwise:
ctl.cust.number - 1234 and 0x1234ABCD
ctl.cust.comment1 - ; line comments
ctl.cust.comment2 - /* block comments */
ctl.cust.string1 - "string"
ctl.cust.string2 - 'string'
ctl.cust.punct
ctl.cust.braceH - brace highlight on cursor event (not yet implemented)
ctl.cust.braceHBad - mismatched brace style, this changes as you edit the doc
ctl.cust.brace - matched brace style, this changes as you edit the doc
ctl.cust.selection (props: all props of Selection object)
ctl.cust.Caret (props: all props of Caret object)
ctl.cust.margin - this is the number margin
ctl.cust.editor - default text color/style/background color
NOTE: When changing editor properties, you need to call ctl.Style.ClearAll()
to apply those settings.
Set property values as if you were using the Style subclass:
the old way:
ctl.Style.ID := 32 ; specify the ID before making changes
ctl.Style.Color := 0x00FF00 ; set a property
the new way:
ctl.cust.number.Color := 0x00FF00
NOTE: The "old way" is still necessary when changing other user-defined styles,
and when applying style settings to other margins that are NOT the typical number
margin (which is usually margin 0). Margin 0 can still be redefined to something
else, and if you choose to do so, you will want to use the "old way" for maximum
flexibility and access to all capabilities provided by the Scintilla library.
For margins, styles, EOL Annotations, and Markers, set the "active ID" like so:
obj.Style.ID := 34 ; make future calls to obj.Style.* apply to style #34
obj.Margin.ID := 2 ; make future calls to obj.Margin.* apply to margin #2
obj.EOLAnn.Line := 3 ; make future calls to obj.EOLAnn.* apply to line #3
obj.Marker.num := 4 ; make future calls to obj.Marker.* apply to marker #4
; NOTE: All methods in the Marker subclass also take a markerNum parameter.
; If you don't specify a markerNum, then the specified num is used.
ctl.SetKeywords(list1, list2, ..., list8)
words should be separated by a space
ctl.cust.kw1.Fore := 0xAABBCC
kw1 - kw8 are available to set. You can set more than just color:
properties: Back, Fore, Font, Size, Bold, Italic, Underline
Once you set the "active ID", future calls to these sub-classes will apply to the most recently set "ID" or "Line", or "marker number" respectively.
2021/08/29
new features
ctl.DefaultTheme()
method to setup 3 keyword list colorsctl.SetKeywords()
methodctl.CaseSense
proerty2021/08/27
bug fixes/new features
/* block comment */
now extends the block comment and styles text accordingly2021/08/26
minor changes
2021/08/25
Features:
2021/08/06
2021/05/17
ctl.Event.MarginWidth()
, with only first two params, can be used to autosize the number margin on-demandctl.AutoBraceMatch := true
2021/05/11
ctl.AutoSizeNumberMargin := true
)2021/05/05
callback(ctl, scn)
I plan to still add the following categories / subclasses listed below. A crossed out item indicates that category of functions has been added.