xeus-r icon indicating copy to clipboard operation
xeus-r copied to clipboard

Better handle history

Open romainfrancois opened this issue 1 year ago • 0 comments

Right now (as of #59), we handle history with a xeus::make_in_memory_history_manager() but this sort of bypass the way R would usually deal with history, which would e.g. give access to history() etc ...

One way to contribute to the history is by calling the C_addhistory routine from the utils:: package, just like what timestamp() does:

> utils::timestamp
function (stamp = date(), prefix = "##------ ", suffix = " ------##", 
    quiet = FALSE) 
{
    stamp <- paste0(prefix, stamp, suffix)
    .External2(C_addhistory, stamp)
    if (!quiet) 
        cat(stamp, sep = "\n")
    invisible(stamp)
}

IIUC, we might have to define these:

extern void (*ptr_R_loadhistory)(SEXP, SEXP, SEXP, SEXP);
extern void (*ptr_R_savehistory)(SEXP, SEXP, SEXP, SEXP);
extern void (*ptr_R_addhistory)(SEXP, SEXP, SEXP, SEXP);

and then probably inherit from history_manager:

History manager
---------------

The ``xhistory_manager`` class is used to store the ``execute_request`` messages sent by the
frontend. Typical usage is when the console client connects to a kernel that has already executed
some code: it asks the ``history_manager`` for its records and prints them so that the user knows
what happened before.

``xeus`` provides a default implementation of ``xhistory_manager`` that stores the messages in
memory. It is possible to provide a different history manager by defining a class that inherits
from ``xhistory_manager`` and implements the abstract methods:

romainfrancois avatar Dec 07 '23 10:12 romainfrancois