M2 icon indicating copy to clipboard operation
M2 copied to clipboard

font lock string face

Open DanGrayson opened this issue 3 years ago • 8 comments

I use the code

(defconst M2-mode-font-lock-keywords ' ( "///\\(/?/?[^/]\\|\\(//\\)*////[^/]\\)*\\(//\\)*///" . 'font-lock-string-face) )

to try to highlight strings delimited by /// ... ///, but the regular expression is so complicated (with backtracking) that it can sometimes cause a delay up to 45 seconds when using C-s to search through a file, as @mikestillman has observed.

We could simplify the regular expression drastically to "///.*///", and not worry about getting every single case correct.

DanGrayson avatar Jun 06 '22 18:06 DanGrayson

I was working on some code a few months ago that might help out with this. Check out https://github.com/Macaulay2/M2-emacs/pull/31.

d-torrance avatar Jun 06 '22 20:06 d-torrance

We could simplify the regular expression drastically to "///.*///", and not worry about getting every single case correct.

You could use "lookarounds" instead.

mahrud avatar Jun 06 '22 20:06 mahrud

We could simplify the regular expression drastically to "///.*///", and not worry about getting every single case correct.

You could use "lookarounds" instead.

Does emacs implement those?

DanGrayson avatar Jun 06 '22 20:06 DanGrayson

I was working on some code a few months ago that might help out with this. Check out Macaulay2/M2-emacs#31.

Would (could) that be ready soon?

DanGrayson avatar Jun 06 '22 20:06 DanGrayson

I was working on some code a few months ago that might help out with this. Check out Macaulay2/M2-emacs#31.

Would (could) that be ready soon?

The part that highlights ///-delimited strings is ready, with the big caveat that it currently breaks syntax highlighting inside doc and TEST strings. That's why I left it as a draft -- I'm not sure if that's a dealbreaker or not.

d-torrance avatar Jun 06 '22 21:06 d-torrance

The desire to highlight the contents of such big strings is perhaps a good argument against doing any highlighting of those big strings as strings.

DanGrayson avatar Jun 06 '22 22:06 DanGrayson

The desire to highlight the contents of such big strings is perhaps a good argument against doing any highlighting of those big strings as strings.

That makes sense! I removed the ///-related commits from M2-emacs#31..

d-torrance avatar Jun 06 '22 23:06 d-torrance

Is this still an issue after https://github.com/Macaulay2/M2-emacs/pull/31?

d-torrance avatar Feb 27 '24 22:02 d-torrance