123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|567|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> neater/ decent way of syntaz highlighting

Fri, 13 Apr 2007, 09:51
oscar
twould seem i'm keeping this place afloat lately with my topics haha (jokes...jokes).

I'm writing a bit of a notepad type program and i've gotten a fair way into it.. but i've hit a snag.

I've started to do some basic syntax highlighting. But my way is ugly as buggery


does anyone know a way of making it look neater (and perhaps not have to update EVERYTHING everytime you hit a key?


*will add a showcase link and upload project*

this is my current code (it executes everytime the rich text box control is changed)

private void RCTdoc_TextChanged(object sender, EventArgs e)
{
//syntax highlighting
StreamReader freader = File.OpenText(Application.StartupPath+"\\test.txt");



string input = null;
int startpos = RCTdoc.SelectionStart;
while ((input = freader.ReadLine()) != null)
{


foreach (Match m in Regex.Matches(RCTdoc.Text, input))
{

RCTdoc.Select(m.Index, m.Length);
RCTdoc.SelectionColor = Color.Blue;
//RCTdoc.SelectionStart = m.Index + m.Length;
RCTdoc.Select(m.Index + m.Length, 0);
RCTdoc.SelectionColor = Color.Black;
//startpos = m.Index+m.Length+1;

}
RCTdoc.Select(startpos, 0);
}
freader.Close();

//end syntax highlighting
if (this.Text.Substring(this.Text.Length - 1, 1) != "*")
{
this.Text = this.Text + "*";
}
}

Fri, 13 Apr 2007, 10:02
Jayenkai
twould seem i'm keeping this place afloat lately with my topics haha (jokes...jokes).

[Insane sarcasm]Well at least we've got a forum to keep afloat!![/insane sarcasm]


Best way to do things is to watch others.

BlitzIDE, for example, seems to update every line individually, and only when a punctuation entity is place, or the cursor moved.
(Example, paste a bunch of text, and watch as it neglects to highlight it correctly)

Programmers Notepad seems to do everything at once, though, so it must use a fairly rapid way of doing things.

Are there any source-code-available ide's out there that you could perhaps have a nosey at? Or maybe ask GrahamK how he got the Cobra one working?

-=-=-
''Load, Next List!''
Fri, 13 Apr 2007, 10:17
oscar
zing!!! it's a good thing i don't have anything to do with sites that don't have forums...lest i be offended.

touche though

getting back on topic... I had a quick look around and they all seem to use some deluded form of class system i.e. the classes are all hopelessly interlinked with each other somehow.

Perhaps if i didn't open the file every time it might go a bit faster

no doubt i'll figure it out.

Some programs seem to only check for changes in the area close to where your editing so that might be an option too..
When the file is first open check the whole thing then afterwards just check the most recent word or something like that.
Fri, 13 Apr 2007, 15:35
JL235
A lot of editors I've used only checks the area where the change is made. Like in BlueJ if you use a multiline comment over lots of code and then uncomment the section, all the lines in the middle are still greyed out.

But could you not use threads? Have one check the whole document and the other check only a single line where a change has been made? Then it should be both responsive and ensure the whole document is correct. Just a thought.