pop-forum syntax highlighting in pop11 -- a simple command

Pop Language

Aaron
A student here asked if Ved could do syntax highlighting, so I
put together a very simple autolodable ved library ved_highlight.p
(contents below)

The command

    ENTER highlight

will underline all syntax words apart from

	brackets, ";", ".", ",". "->", "^", "^^",

and others in the list

	highlight_exceptions


The new library is now in $usepop/pop/lib/ved/ in the latest version
of poplog from here:

    http://www.cs.bham.ac.uk/research/projects/poplog/v15.61/

(Help file to be written when design finalised!).

The new file can be downloaded on its own from

    http://www.cs.bham.ac.uk/research/projects/poplog/v15.61/v15.61/pop/lib/ved/ved_highlight.p

and installed in an existing poplog system in the directory

    $usepop/pop/lib/ved/

It will then be autoloadable.

It is very short. If necessary it could be changed to use bold
instead of underlining by replacing the line

            veddo('chat -w u');

with
            veddo('chat -w b');

To get ordinary highlighting (reverse video) use
            veddo('chat -w 1');

(Should that be the default instead of underlining?? I found
it a bit harsh.)

Syntax words could be made to flash by using 'f' instead of 'u', but
I think that is horrible. Other options are to make them coloured
but only in Xved. The underlining works in ordinary ved in an xtem
window.

The program uses the 'ENTER chat' (CHangeATtribute of characters)
command. documented in

    REF ved_chat

The highlighting can be undone by
    ENTER strip

(Essential before printing files, alas.)

In XVed it would be possible using the ved_chat facilities to use
different colours for different types of syntax word, but I did not
think that worth the effort.

Also getting a default that works both for people who always use
reverse video (like me) and people who use black on white (the
majority) could be difficult. (As I have found with the 'coloured'
version of the 'ls' command.)

Has anyone else done anything like this. If so it is probably better
than my version -- done in a few minutes.

Actually I was amazed at how simple the program turned out to be.

Aaron
===

/* --- Copyright University of Birmingham 2007. All rights reserved. ------
 > File:			 $usepop/pop/lib/ved/ved_highlight.p
 > Purpose:			
 > Author:			Aaron Sloman, Nov 22 2007
 > Documentation:
 > Related Files:
 */

section;

;;; items not to be highlighted (edit if you wish)
global vars
	highlight_exceptions =
        [% "(", ")", "[", "]", "{", "}", ";", ":", ",", ".", "%",
			"->", """, "^", "^^", "!" %];

define ved_highlight;

    ;;; save current position;
    vedpositionpush();

    ;;; jump to top of file
    vedtopfile();
    ;;; highlight every syntax word in file

    repeat
        quitif(vedatend());
        lvars item = vedmoveitem();
        if is_syntax_word(item)
        and not(lmember(item, highlight_exceptions))
        then
            ;;; underline item just read
            ;;; (change 'u' to 'b' for bold, or to '1' for reverse video)
            veddo('chat -w u');
        endif;
    endrepeat;

    ;;; jump to saved position
    vedpositionpop();
enddefine;

endsection;                                            
spamsofluccoukinvalid
Or you could have saved yourself some time, and used the library I
made available (on the poplog-dev mailing list) several years ago, (in
2002 or earlier) which (optionally) does syntax highlighting while you
type.

I don't have a copy on this machine, or I'd post it. (I no longer have
it webbed, either.)

I think, five years ago, you disapproved of syntax highlighting, and
thought it was a waste of time - which might be why you didn't have a
copy (or remember it, if you do have one). I gather you've changed your
mind?

Jonathan