M2 icon indicating copy to clipboard operation
M2 copied to clipboard

Syntax highlighting in packages

Open mahrud opened this issue 1 year ago • 5 comments

A pretty glaring caveat of syntax highlighting is that it doesn't work for packages. Here's an example with only symbols from Core being highligted, which looks really odd.

A pretty simple solution would be to generate a prism grammar for each package in installPackage and load it in the header of html files from that package.

It would be great if the same worked for emacs.

mahrud avatar Jun 25 '24 05:06 mahrud

There are also a few related suggestions in .https://github.com/Macaulay2/M2/pull/3298.

mahrud avatar Jun 25 '24 05:06 mahrud

(copied from zulip) a tangentially related issue. Say one defines a new function myfunc, then neither in emacs nor in the webapp will the autocompletion work if one types say myf followed by tab. However it does work in the terminal using readline. Why can't we have something similar without readline? it can't be that hard...

pzinn avatar Jul 03 '24 07:07 pzinn

@d-torrance's answer:

I've played around with this a bit. We could potentially do something like call apropos to get a list of possible autocompletions, but output it in such a way that the editor doesn't display the output to the user. This is basically how autocompletion works in the Python Emacs mode

originally I was hoping we could reuse the code made for readline but I guess most of the work is done by readline itself...

pzinn avatar Jul 03 '24 07:07 pzinn

continuing my digression, I'm assuming this is the relevant part of expr.d:

export completions(s:string):array(string) := (
     n := length(s);
     if n == 0 then return array(string)();		    -- don't complete the null string
     v := newvarstringarray(6);
     d := globalDictionary;
     while (
	  lockRead(d.symboltable.mutex);
	  foreach bucket in d.symboltable.buckets do (
	       b := bucket;
	       while true do when b
	       is null do break
	       is q:SymbolListCell do (
		    t := q.word.name;
		    if isalnum(t.0) && n <= length(t) && 0 == strncmp(s,t,n) then append(v,t);
		    b = q.next; ));
	  unlock(d.symboltable.mutex);
	  d != d.outerDictionary) do d = d.outerDictionary;
     extract(v));

pzinn avatar Jul 03 '24 23:07 pzinn

It is not a digression. Syntax highlighting and autocompletion have the same purpose.

mahrud avatar Jul 04 '24 03:07 mahrud