View Raw SPL
#include 

static ucu = "";

editline(h, s)
{
        local idx, t, len, line, y, xoff;

        if (argc < 2)
        {
                if (argc < 1) return(s);
                
                s = refseries(w0);
        }

        ucu = getconf("units_convert_hunits");
        setconf("units_convert_hunits", "0");

        /* coordinates of edit line */
        line = h.coords;

        /* interpolate to deltax if interval series */
        if (not(ISXYSERIES(s)))
        {
                line = xyinterp(line, deltax(s));
        }

        /* convert x values to indices */
        idx  = xtoidx(s, xvals(line));
        xoff = xoffset(s);

        if ((len = length(idx)) > 1)
        {
                /* check for prepend */
                if (max(idx) <= 1)
                {
                        y    = concat(line, s);
                        xoff = min(xvals(line));
                }
                else if (max(idx) >= length(s))
                {
                        /* append */
                        y = concat(s, line);
                }
                else
                {
                        /* insert */
                        y = concat(extract(s, 1, idx[1] - 1), line, extract(s, idx[len] + 1, -1));
                }

                /* update units, etc. */
                setvunits(y, getvunits(s));
                sethunits(y, gethunits(s));
                setxoffset(y, xoff);
                setyoffset(y, yoffset(s));
                setplotstyle(y, getplotstyle(s));
        }
        else
        {
                y = refseries(s);
        }

        setconf("units_convert_hunits", ucu);
        ucu = "";

        return(y);
}


editline_error(errnum, errmes)
{
        if (strlen(ucu) > 0)
        {
                setconf("units_convert_hunits", ucu);
        }
        
        error(sprintf("[editline] %s", errmes));
}