Skip to content

Commit

Permalink
simplify syntax highlighting code
Browse files Browse the repository at this point in the history
this is a rewrite of the syntax highlighting code. overall it's a
salmon-colored patch (deleted more than added), the code is easier to
follow, and it fixes some long-standing bugs.

as noted in the readme, there was a bug involving overlapping rules.
the most annoying instance of this bug was with strings containing a
`/*` such as in glob patterns. for example:

```
"match/this/path/*"
```

with `syn_generic` applied, we used to interpret `/*` as the
beginning of a multi-line comment, and therefore the rest of the file
(or until there happened to be a closing `*/` somewhere). this
bothered me for a very long time.

this bug was due to how we used to apply rules. each rule would get
applied one after the other, each from the beginning of the line. the
last rule to style any given span of text superseded any previous
rules that matched.

in the rewrite, once a rule matches a span of text, we don't try to
style that span anymore (until the text is edited of course).

the one downside is that this seems to be slightly less performant.
on my machine, applying `syn_generic` is about 5% slower, but it's
still generally fast enough that you'd only start to notice the
difference if you were opening massive files, tens or hundreds of
megabytes large, with syntax highlighting on. a memo field was added
(`smemo_t`) which drastically improved perf. there are probably
further perf optimizations to be had.

i added a couple more functional tests, on top of the existing ones,
to exercise some edge cases of syntax highlighting. as always please
report bugs if you find any.
  • Loading branch information
adsr committed Apr 30, 2023
1 parent 41f6919 commit 7231152
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 251 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ be mapped to keys as normal via `-k`. See `uscript.lua` for a simple example.
There is also a `wren` branch with [Wren](http://wren.io) scripting support.
That work is on pause.

### Known bugs

* Multi-line style rules don't work properly when overlapped/staggered.

### Forks

* [eon](https://github.com/tomas/eon) - mouse support and Notepad-like
Expand Down
Loading

0 comments on commit 7231152

Please sign in to comment.