[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Feb 22 09:06:46 1993 
Subject:Re: Running Ved from Ved 
From:Aaron Sloman 
Volume-ID:930222.03 

popx@vax.oxford.ac.uk writes:

> Date: 21 Feb 93 20:58:41 GMT
> Organization: Oxford University VAX 6620
>
> I wonder whether anyone can help with a Ved problem?

I append the reply I sent to the pop-forum email list.
-------------------------------------------------------------------

> Here comes the problem. How do I invoke editing from inside a procedure
> called by Ved? I thought that -edit(<filename>)- would do. According to
> REF VEDPROCS, it "calls the editor with the file, whether in VED or
> not". However, when I call it inside -simulate-, it immediately returns,
> and doesn't allow the user to edit.

REF VEDPROCS is inaccurate on this point and should be corrected. If VED
is already already running then edit(<file>) behaves as equivalent
roughly to

    vededitor(vedveddefaults, <file>)

(SHOWLIB EDIT, makes the equivalence clear.)

The entry for REF VEDPROCS/vededitor is more accurate. It says:

        If  this  procedure  is  called  from  inside  VED  (i.e.   when
        -vedinvedprocess- is already true), it simply calls

            vedgetfile(DEFAULTS_P, VEDFILE).

        and returns.

I.e. the file is simply read in (if necessary) and put at the front of
vedbufferlist, and made the "current" file so that procedures like
vedcharinsert, vedinsertstring, vedthisline, etc. and VED's global
variables refer to the file. It is also displayed on the screen if
necessary.

The reason nothing more is done is that if you are already in VED there
is already a top level loop reading in characters from the terminal, so
there is no need for vededitor, or edit, to set up a new one. If you
wish to set up a new one it can be tricky to exit from it, but there are
various things you can try.

This has become harder since the advent of Xved because more complicated
mechanisms had to be used to cope with the interaction with
Xved windows.

Anyhow, here's something that you can try, which may, in some ways,
be a bit more general than you need.
(Something like this should be available to users as a library utility).


define ved_get_and_edit(file);
    lvars
        file,           ;;; file to switch to.
        oldfile = vedcurrentfile;   ;;; file to return to

    define dlocal ved_q();
        ;;; redefine ved_q locally to return to old file,
        vededitor(identfn, oldfile);
        ;;; then exit from ved_get_and_edit
        exitfrom(ved_get_and_edit)
    enddefine;

    ;;; make the specified file current, after saving the oldfile
    edit(file);

    ;;; Invoke a replica of VED's top level loop, to be left when
    ;;; ved_q is invoked
    runproc(0, consproc(0,vedprocess));
enddefine;


/* test the above using mark and load

    ;;; make mapping to ved_q "soft", by mapping to word not procedure
    vedsetkey('\^[q', "ved_q");

    ;;; Now try this
    ved_get_and_edit('foo');
*/

If that doesn't work, you could try this version.

define ved_get_and_edit(file);
    lvars
        file,           ;;; file to switch to.
        oldfile = vedcurrentfile;   ;;; file to return to

    define dlocal ved_q();
        ;;; redefine ved_q locally to return to old file,
        vededitor(identfn, oldfile);
        ;;; then exit from ved_get_and_edit
        exitfrom(ved_get_and_edit)
    enddefine;

    ;;; make the specified file current, after saving the oldfile
    edit(file)

    ;;; simulate a subset of VED's top level loop, to be left when
    ;;; ved_q is invoked
    repeat
        ;;; get next command and obey it
        vedprocesschar();
        ;;; now sort out display
        if vedonstatus then
            vedsetstatus(nullstring, false, undef);
        else
            vedsetstatus(vedmessage, vedmessage /= nullstring, undef);
        endif;

        ;;; ensure cursor location is visible
        vedcheck();
        ;;; update cursor location after move procedures
        vedsetcursor();
    endrepeat;
enddefine;


> Secondly, even if I could invoke the editor, how would I redefine
> a key temporarily? I need to redefine a key (haven't decided which one)
> so that hitting it causes a return from editing, back to the simulator.

I tried to illustrate that in the example above. Use vedsetkey (or
"vedset keys") to ensure that the key sequence that normally invokes
the procedure calls it via the procedure name, by using a word as
second argument. (It must be a "global" variable, or defined in the
current section, so that VED can get at it via valof.).

Then inside ved_get_and_edit, redefine that procedure locally to
return to the previous file (if you wish) then exitfrom
ved_get_and_edit.

> Incidentally, this key can't be ENTER, because I want the user to be able
> to give ENTER commands from here.

I think that will work with the above procedure.

If John Gibson is reading this, he will probably give you a better
solution!

Aaron
--
-- 
Aaron Sloman,
School of Computer Science, The University of Birmingham, B15 2TT, England
EMAIL   A.Sloman@cs.bham.ac.uk  OR A.Sloman@bham.ac.uk
Phone: +44-(0)21-414-3711       Fax:   +44-(0)21-414-4281