On 23 Apr 2001, Lars Gullik [iso-8859-1] Bjønnes wrote:

> Allan Rae <[EMAIL PROTECTED]> writes:
>
>  * Just a thought spun-off from this work: using addition-order and a
>  * simple class we could have macro-recording and playback of LyXFunc
>  * actions in a few lines of code.
>
> That can be done a lot simpler.
>
> For macro:
>         - add two new LFUN's macro-begin and macro-end
>         - record (in Dispatch) all commands accessed between a
>           macro-begin and macro-end pair.
>
> Playback of complete session:
>         - just record every LFUN and store it to file.
>         - add a command arg that "runs" this file

Sure, only the implementation I was thinking of had a:
        vector<pair<LFUN, string arg> >

instead of a file and whenever you press macro-begin when already
recording the record starts again.

I had considered doing something fancy like:
        vector<LFUNAction>

struct LFUNAction {
        LFUNAction(LFUN, string const &);
        void operator() ();

private:
        string what_the_arg_was;
        LFUN what_the_dispatch_number_was;
};

So the LFUNAction gets created and appended to the vector.  Then to replay
the macro you just iterate over the vector and execute the LFUNAction's.

There are plenty of possible tweaks to do here and I've probably
overlooked stuff.  The good thing is that we can effectively record most
dialog interaction as well so long as the dialog calls LyXFunc->Dispatch
to get its outputs set (ie. when you press OK).

The first version instead lets you create a:

struct LFUNAction {
        void operator() (pair<LFUN, string>);
};

for_each(macro.begin(), macro.end(), LFUNAction());

I wasn't intending to allow recorded macros to last longer than the
duration of an editting session, unless, like emacs, you name the macro.
Then you have the name of the macro file to use also.

Allan. (ARRae)

Reply via email to