driusan / de

A Programmer's Text Editor
MIT License
428 stars 26 forks source link

shell syntax highlighting #24

Open josephholsten opened 8 years ago

josephholsten commented 8 years ago

it's safe to say that (bourne) shell is a popular language. it would be neato to have syntax highlighting.

josephholsten commented 8 years ago

hopefully I will be able to collect enough caffeine this weekend to attempt it. anyone got suggestions of an external syntax highlighting plugin that would be useful to study? the only kind I've played with in the past was textmate, and that was a very unique approach.

driusan commented 8 years ago

I'm not sure what you mean by "external syntax highlighting plugin". If you mean de plugins which are external to this repo that do syntax highlighting, I don't know of any, you might be the first. If you mean external tools which do syntax highlighting, I'm not sure that studying them would be incredibly useful, since I don't think many of them use same approach of just having the viewport be an image that gets drawn to using a TTF font (especially since a lot of them are for the console..)

The easiest place to start is probably the de renderers/nosyntax/ renderer. The ones that add syntax highlighting basically take that as a starting point, but for each character as it's ranging through the runes tries to keep track of where it is in the language's context based on what it knows about what it's rendered so far (and maybe doing a comparison on a slice of the runes at the current index to look ahead to see if it's the start of a keyword), then changes the writer.Src to a new colour when the context changes (ie. if it's inside a string and it sees a string terminator, it changes the colour back to the default after drawing the closing quote.)

I've been meaning to extract the code that's in common so that more is shared between the renderers and they only need to figure out the colourization, but I haven't had a chance yet.

josephholsten commented 8 years ago

Ah, I just meant I want sure if it was worth reading through the sh syntax plugin used in another editor, like atom, emacs, vim, &c.