Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily Disable History Logging #12927

Open
jdtsmith opened this issue Apr 22, 2021 · 1 comment
Open

Temporarily Disable History Logging #12927

jdtsmith opened this issue Apr 22, 2021 · 1 comment

Comments

@jdtsmith
Copy link
Contributor

jdtsmith commented Apr 22, 2021

I'm working to improve Emacs interaction with iPython. Emacs sends many commands to iPython "behind the scenes", hiding the output. This causes iPython to update the history execution counter, and also pollutes In (and _, _2, etc.).

Is there a way to ask iPython to run a command but not record it in In/Out or update the execution counter (i.e. "off the books")?

This "sort of" works but leads to an error:

In [9]: _ip.execution_count -= 1; print('OK?')
OK?

ERROR! Session/line number was not unique in database. History logging moved to new session 483
In [9]: 
@jdtsmith
Copy link
Contributor Author

Here's what I came up with reading the source (not sure if it's kosher but works):

class __ipb_run:
    def __init__(self):
        self.ip=get_ipython()
        self.hm=self.ip.history_manager
    def run_and_erase_tracks(self,command):
        exec(command)
        self.ip.execution_count-=1
        del self.hm.input_hist_parsed[-1]
        del self.hm.input_hist_raw[-1]
        self.hm.db_input_cache.clear()
__ipb_runner=__ipb_run()

and using it:

In [50]: __ipb_runner.run_and_erase_tracks("print('supertopsecret')")
supertopsecret

In [50]: x=5; x
Out[50]: 5

In [51]: _50
Out[51]: 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant