View Raw SPL
#include 

static in_vedit, cursor, tagstr, ltarg;

extern _vedit_w, _vedit_c;

/* visually edit a series with mouse cursor */
vedit(w, color)
{
        (w, color) = vedit_parse_args(w, color);

        /* set to pen cursor */
        cursor = getconf("line_cursor");
        setconf("line_cursor", "-17");

        /* tag string */
        tagstr = getconf("line_tag");
        setconf("line_tag", "editline");

        /* line target */
        ltarg = getconf("line_target");
        setconf("line_target", "0");

        /* draw edit lines */
        vedit_loop(w, color);

        /* restore cursor */
        setconf("line_cursor", cursor);
        cursor = "";

        /* restore tag */
        setconf("line_tag", tagstr);
        tagstr = "";

        /* restore target */
        setconf("line_target", ltarg);
        ltarg = "";
}


/* draw edit lines */
vedit_loop(w, color)
{
        local h;

        w        = castwindow(w);
        in_vedit = 0;

        if (length(w) > 0)
        {
                in_vedit = 1;

                /* source window */
                moveto(w);

                /* line cursor */
                h = linecur(color);

                /* set tag so we can track the line */
                if (ishandle(h))
                {
                        h.showtag = 0;
                        h.tag     = "editline";

                        /* renter edit loop */
                        _vedit_w = castwindow(w);
                        _vedit_c = color;
                        
                        pushkey(strescape("vedit(_vedit_w, _vedit_c)\r"));
                }
        }

        in_vedit = 0;
}


/* reset cursor on error */
vedit_error(errnum, errmes)
{
        if (strlen(cursor) > 0)
        {
                setconf("line_cursor", cursor);
                cursor = "";
        }

        if (strlen(tagstr) > 0)
        {
                setconf("line_tag", tagstr);
                tagstr = "";
        }
        
        if (strlen(ltarg) > 0)
        {
                setconf("line_target", ltarg);
                ltarg = "";
        }

        in_vedit = 0;
        
        error(errmes);
}


/* visual edit in progress */
is_vedit()
{
        return(in_vedit);
}


vedit_parse_args(w, color)
{
        local winstr;

        if (argc < 2)
        {
                if (argc < 1)
                {
                        w     = castwindow(0);
                        color = lred;
                }
                else
                {
                        if (isscalar(w))
                        {
                                color = w;
                                w     = castwindow(0);
                        }
                        else
                        {
                                color = lred;
                        }
                }
        }

        if (not(iswindow(w)))     error("vedit - invalid series argument");
        if (not(isscalar(color))) error("vedit - invalid color argument");

        winstr = strwin(w);

        return(winstr, color);
}