How do I set the lexer language?

Topics: Developer Forum
Sep 8, 2006 at 5:30 PM
(Big apologies in advance if I'm missing something totally obvious...)

I got the latest source (changeset 5315), and it built cleanly, and I can run the "scide" project (woohoo!). The source looks great, guys.

Anyway, I want to try to tell the control that I'm in a certain language, like VBScript or CSS or Ruby, to get syntax highlighting. I see the Lexer enum, but don't see a property on the control to set that (just to get it).

So near the end of the FormScintillaContainer constructor, I've tried:

scintillaControl.LexerLanguage = "ruby";

but nothing seems to be different when I run the app (no syntax highlighting that I would expect).

So I'm thinking either I'm using the wrong property or method, or maybe syntax highlighting just isn't implemented yet?

Thanks!
Jeff
Sep 8, 2006 at 5:33 PM
I should also add, I see now that .Lexer is get/set, but this:

scintillaControl.Lexer = (int)Scintilla.Enums.Lexer.Ruby;

didn't seem to help either.
Sep 8, 2006 at 6:09 PM
I have a feeling that the syntax highlighting is part of what Garrett is in the middle of adding right now. Since he's busy at his real job (I know how that is!), it may be a while before he finishes it. I'm really not sure how long.
Coordinator
Sep 8, 2006 at 8:08 PM
Yeah this particular build doesn't contain any automatic styling engine at all. To get it to work you'd have to set up your own style rules and keywords manually.

Your options are:
Wait until Garett adds his latest and greatest configuration system to the project. (Maybe we should bug him to at least check in what he has and we can hack away at it)

Do your own styling using a combination of the StyleSetXXX methods and StyleSetKeyWords Methods (see the Scintilla Documentation http://scintilla.sourceforge.net/ScintillaDoc.html for details)

If you download the old SourceForge version (http://sourceforge.net/projects/scide) you'll find an old implementation of an XML based configuration system. It wouldn't be too difficult to integrate it into the latest codebase.
Sep 8, 2006 at 9:16 PM
I don't see the StyleSetKeywords method.

I did try this without luck:

scintillaControl.Lexer = (int)Scintilla.Enums.Lexer.Ruby;
scintillaControl.StyleSetFore((int)Scintilla.Lexers.Ruby.ClassName, Color.Blue.ToArgb());

and then typed this into the control at runtime:

class Jeff
end

but 'Jeff' was still black, not blue.

I guess we should wait for Garet's new scheme... hate to go back to the old xml implementation.
Coordinator
Sep 12, 2006 at 10:50 PM
Sorry guys, I'm SOOOO crammed right now, between RTM deliver commitments, and the fact that I'm actually in Santa Clara at a conference right now, and I've been meeting with clients by the metric truckload. ScintillaNET won't get any attention for another week or 10 days.

I Do have the majority of the styling persistence done, it's not much of a divergence from the old xml stuff, except that it comes completly stocked with about 60 languages all setup. (I've got that data done already :D ).

Once I've got that all done, I'll check that in and everyone will rejoice. :D

G
Sep 25, 2006 at 7:15 PM
Garett - just wondering if you've had a chance to look at the syntax highlighting stuff yet? Totally understand you've been swamped lately - just curious/anxious to get the indenting/coloring to work.

Thanks!
Jeff
Sep 27, 2006 at 4:51 AM
I just added the old config file code from the previous version of the project into the new project. I tried the C# lexer and it seems to work. Hope it helps y'all.
Oct 16, 2006 at 5:02 PM
> Once I've got that all done, I'll check that in and everyone will rejoice. :D

Are we any closer to rejoicing yet? :-)

I've played with the old XML settings, and it's kind of a royal pain... any chance you'll be able to check in your new work soon?

Thanks!
Jeff
Oct 19, 2006 at 2:54 PM
I'm having deja vu here. On the last couple Scintilla.Net projects Garret became so busy/distracted that the project went dormant for a year or two. (no offence Garrett, I know where you're coming from!) There is a difference now. There are 3 or 4 of us on the project than can probably implement a new configuration system if we want to. If you have an idea of how you'd like it to work, why don't you post your ideas on here and we can just implement it ourselves. If you arn't part of the project, maybe you can email garret and get added to the list.
Oct 19, 2006 at 3:53 PM
> There are 3 or 4 of us on the project than can probably implement a new configuration system if we want to. If you have an idea of how you'd like it to work, why don't you post your ideas on here and we can just implement it ourselves.

Awesome... well, here's what I'm looking for:

- Scite-like color-coding for the languages Scite currently supports. It would great to be able to migrate an existing .properties file, for example. I actually think the file format they used works pretty well (and is a whole lot easier on the eyes than xml). I've been able to understand it just enough to hand-tweak my colors and fonts, though I'm not totally clear on the difference between which are "system defaults" and which can be overridden by a particular .properties file.

- Some kind of delegate hook or event mechanism so that my code can have a chance to intercept ctrl-space for showing an intellisense or autocomplete dropdown, for example. And also easy access to the contents of the current line/method/group - this depends on the particular file being edited (css, vs. C#, vs. Ruby, etc.) but Scite seems to understand how to fold each of these types appropriately. If I could programttically get at the "current line" and maybe walk "upwards" a fold at a time, that would be awesome.

I haven't had a chance to spend enough time with the code yet to know if these things are easy, kind of hard, or impossible (and maybe it's just me, but the documentation on scintilla.net makes my eyes glaze over, so trying to figure out how to write the color coding system was hard for me). But I am certainly willing to put in some "sweat equity" if no one else has the time and I can get a hint or two about where to start.

Sorry for the long post... let me know what you think.

Thanks!
Jeff
Oct 19, 2006 at 6:33 PM
I like the idea of supporting scites configuration files. At some point, if Garrett posts his cool new configuration system, this doesn't have to get in the way.
Oct 26, 2006 at 7:39 PM
Since Garrett seems to have disappeared into the ether again, let me ask a couple more questions...

(And again, apologies in advance if these seem dumb - I feel like I'm missing something rather obvious as I try to grasp the scope of the "scintilla ecosystem" here. For each question, feel free to just point me to a url with more information if that's easiest.)

- Can we just use SciLexer.dll that comes with scite, and we just need to tell our IDE to use it? If so, how is our code supposed to manage communication between scilexer.dll and our .exe?

- Or, are we faced with writing our own lexer according to http://scintilla.sourceforge.net/Lexer.txt? If so, have we already started this, and if so what section of our code is trying to do this?

My schedule frees up a bit starting next week so I would have some time to play with this and contribute if I can come up with something that works.

Thanks again!
Jeff

Oct 27, 2006 at 2:58 AM
I think all we have to do is read in the .properties files (like scite has) and apply it to properties and methods on the Scintilla control. Those files look a little goofy, but it's just text and I'm sure the format is well documented..
Oct 27, 2006 at 3:54 PM
Well, I don't think so, unless I'm just doing it wrong. Code like this seems to have no effect at all:

scintillaControl.Lexer = (int)Scintilla.Enums.Lexer.Ruby;
scintillaControl.StyleSetFore((int)Scintilla.Lexers.Ruby.ClassName, Color.Blue.ToArgb());

so I'm thinking there are some dots that still need connecting somewhere, and maybe that's what Garrett was in the middle of doing before he disappeared.
Oct 30, 2006 at 11:06 PM
Hey guys, this project looks like it is exactly what I have been looking for. I am in need of a .NET control that provides syntax colouring and some other features that it looks like scintilla supports. Is it possible to get the current release of this system to provide syntax highlighting (even if it is a bit hackish)?
Nov 2, 2006 at 11:33 PM
Well, I got ScintillaNET up and running, and with minor changes I was able to get highlighting, line numbers, and folding all working. Too bad about the new config system, but the old xml one works fine for me. Thanks guys! Great work!
Nov 3, 2006 at 2:24 AM
Great! would you care to post the modifications you made in order to get all this working ?
Nov 15, 2006 at 4:21 PM
Resource\Scintilla.iface: line 1685
change from
set void SetProperty=4004(string key, string value)
to
fun void SetProperty=4004(string key, string value)

Otherwise it wasn't generating that function.

ScintillaNET\EventArgs.cs: line 179
from
internal SCNotification SCNotification
to
public SCNotification SCNotification

ScintillaNET\EventArgs.cs: line 184
from
internal NativeScintillaEventArgs(Message Msg, SCNotification notification)
to
public NativeScintillaEventArgs(Message Msg, SCNotification notification)

These two changes were made so that I could access those two classes. They are needed to set up line numbers.

I think that is all I added. Not sure though.

Also, here is some of my code that sets up folding, line numbers, and the legacy highlighting.

// Add Scintilla.Net Legacy Support

// create the configuration utility.
// you need to pass a type that exists int the assembly where the class that you use as
// a base node for configuration.
Scintilla::Legacy::Configuration::ConfigurationUtility^ cu = gcnew Scintilla::Legacy::Configuration::ConfigurationUtility(GetType()->Module->Assembly);

// set the configuration to scintilla
config_ = (Scintilla::Legacy::Configuration::Scintilla^)cu->LoadConfiguration(Scintilla::Legacy::Configuration::Scintilla::typeid, "LegacyScintillaNET.xml");

scintillaControl->LegacyConfiguration = config;

// change the language. It automatically changes the lexer for you based on the settings
// in the config file.
scintillaControl_->LegacyConfigurationLanguage = "lua";

// Enable smart indenting
scintillaControl_->SmartIndentingEnabled = true;
scintillaControl_->TabWidth = 4;

// Text Line Numbers
scintillaControl_->MarginWidthN(0, 30);

// Folding
scintillaControl_->SetProperty("fold", "1");
scintillaControl_->SetProperty("fold.compact", "0");
scintillaControl_->MarginTypeN(2, 0);
scintillaControl_->MarginMaskN(2, (int)0xFE000000);
scintillaControl_->MarginWidthN(2, 16); // May need 20
scintillaControl_->MarginSensitiveN(2, true);
scintillaControl_->SetFoldFlags(16); // 16 Draw line below if not expanded

scintillaControl->MarginClick += gcnew System::EventHandler<Scintilla::MarginClickEventArgs^>(this, &Editor::ScriptToolWindow::scintillaControlMarginClick);

scintillaControl->MarkerDefine(30, Scintilla::Enums::MarkerSymbol::Plus); // SCMARKNUM_FOLDER
scintillaControl->MarkerDefine(31, Scintilla::Enums::MarkerSymbol::Minus); // SCMARKNUM_FOLDEROPEN
scintillaControl->MarkerDefine(25, Scintilla::Enums::MarkerSymbol::Empty); // SCMARKNUM_FOLDEREND
scintillaControl->MarkerDefine(27, Scintilla::Enums::MarkerSymbol::Empty); // SCMARKNUM_FOLDERMIDTAIL
scintillaControl->MarkerDefine(26, Scintilla::Enums::MarkerSymbol::Minus); // SCMARKNUM_FOLDEROPENMID
scintillaControl->MarkerDefine(29, Scintilla::Enums::MarkerSymbol::Empty); // SCMARKNUM_FOLDERSUB
scintillaControl->MarkerDefine(28, Scintilla::Enums::MarkerSymbol::Empty); // SCMARKNUM_FOLDERTAIL
Coordinator
Jan 21, 2007 at 5:21 AM
Hrm, I could have sworn somebody has done this already...

I have a working implementation of the old styling system from SourceForge.
Coordinator
Jan 25, 2007 at 8:30 PM
Yep, jgreenwood did. LegacyConfigurationLanguage
Feb 25, 2007 at 9:19 AM
I've actually just finished a parser class for the Scite config files. I'll be checking that in soon with just style support. We can add functionality as we go, but this will be a starting point.
Feb 28, 2007 at 6:52 AM
For anyone that is interested, I've implemented an already advanced config system and it's all built into ScIDE. Just try to open a code file or html and you'll see what it's capable of
Feb 28, 2007 at 1:18 PM
I am using ScintillaNET for my .net based project.Can somone help me with the code for folding and autoindentation ?
Feb 28, 2007 at 2:14 PM
Edited Feb 28, 2007 at 2:47 PM
Well, you ovbiously have not looked at the latest version of Scintilla.Net. Sync up (or download the source) and open up a C# or HTML file. Folding and auto-indent are built in already. Ther code is all in the ScintillaControl class.

Change Set 19188
http://www.codeplex.com/ScintillaNET/SourceControl/DownloadSourceCode.aspx?changeSetId=19188
Mar 7, 2007 at 8:55 AM
I know ScintillaNet supports folding but i don't know how to use this feature of scintilla through my C# code.Can you help me on this ?
Mar 7, 2007 at 2:28 PM
Here is the code used to configure folding the ScintillaNet control. You can use this in conjunction with the Scintilla documentation on the scintilla website to get all the answers you need. You're going to have to research it out a little if you want to use it. This project is still young and there is no documentation other that that on the Scintilla website.

    if (enableFolding)
    {
        this.Property("fold", "1");
        if (conf.FoldCompact.HasValue) this.Property("fold.compact", (conf.FoldCompact.Value ? "1" : "0"));
        if (conf.FoldComment.HasValue) this.Property("fold.comment", (conf.FoldComment.Value ? "1" : "0"));
        if (conf.FoldPreprocessor.HasValue) this.Property("fold.preprocessor", (conf.FoldPreprocessor.Value ? "1" : "0"));
        if (conf.FoldHTML.HasValue) this.Property("fold.html", (conf.FoldHTML.Value ? "1" : "0"));
        if (conf.FoldHTMLPreprocessor.HasValue) this.Property("fold.html.preprocessor", (conf.FoldHTMLPreprocessor.Value ? "1" : "0"));
 
        this.MarginWidthN(1, 0);
        this.MarginTypeN(1, (int)MarginType.Symbol);
        this.MarginMaskN(1, unchecked((int)0xFE000000));
        this.MarginSensitiveN(1, true);
 
        if (conf.FoldMarginWidth.HasValue) this.MarginWidthN(1, conf.FoldMarginWidth.Value);
        else this.MarginWidthN(1, 20);
 
        if (conf.FoldMarginColor != Color.Empty) this.SetFoldMarginColor(true, Utilities.ColorToRgb(conf.FoldMarginColor));
        if (conf.FoldMarginHighlightColor != Color.Empty) this.SetFoldMarginHiColor(true, Utilities.ColorToRgb(conf.FoldMarginHighlightColor));
        if (conf.FoldFlags.HasValue) this.SetFoldFlags(conf.FoldFlags.Value);
        
        this.MarkerDefine((int)MarkerOutline.Folder, MarkerSymbol.Plus);
        this.MarkerDefine((int)MarkerOutline.FolderOpen, MarkerSymbol.Minus);
        this.MarkerDefine((int)MarkerOutline.FolderEnd, MarkerSymbol.Empty);
        this.MarkerDefine((int)MarkerOutline.FolderMidTail, MarkerSymbol.Empty);
        this.MarkerDefine((int)MarkerOutline.FolderOpenMid, MarkerSymbol.Minus);
        this.MarkerDefine((int)MarkerOutline.FolderSub, MarkerSymbol.Empty);
        this.MarkerDefine((int)MarkerOutline.FolderTail, MarkerSymbol.Empty);
 
        this.MarginClick += new EventHandler<MarginClickEventArgs>(ScintillaControl_MarginClick);
    }
Mar 8, 2007 at 6:37 AM
Thanks for your support but what is "conf" here ?
Mar 8, 2007 at 2:05 PM
In the context above, "this" is the ScintillaControl. (This snippit is from the set property "ScintillaControl.ConfigurationLanguage") ...and "conf" is the ScintillaConfig object that I wrote last week. It reads in config settings from the SciTE config files provided in the C++ version of the editor.