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

Tweaks on async ipython #145

Merged
merged 6 commits into from
Nov 2, 2017
Merged

Tweaks on async ipython #145

merged 6 commits into from
Nov 2, 2017

Conversation

et2010
Copy link
Contributor

@et2010 et2010 commented Oct 30, 2017

Those commits includes following tweaks:

  • support :noweb code reference
  • Fixed How to preserve leading whitespace for ob-ipython-results :text/plain? #140
  • Rewrite company backend, completion is now more robust.
  • Replace org-babel-get-src-block-info whenever possible. That function is too heavy, causing lag to evaluation or completion. The performance is improved a lot upon this change. As I can tell, at least the completion is more responsive.
  • Rework results rendering. When :results is set to output, it will use the output as results. If no output is available, it will generate a reasonable fake output from ipython evaluation. When :results is set to value, you can use the :ob-ipython-results header arg to specify the result type you want. Inspired by ob-ipython, I also added a text/org type that can be used to format pandas dataframe as org table (tabulate.py is needed). To use it, you shoud add a ipython startup file:
#!/usr/bin/env python
import IPython
from tabulate import tabulate
from pandas import Index

class OrgFormatter(IPython.core.formatters.BaseFormatter):
    def __call__(self, obj):
        try:
            if isinstance(obj, Index):
                raise Exception('Do not format Index object!')
            return tabulate(obj, headers='keys',
                            tablefmt='orgtbl', showindex='always')
        except:
            return None

ip = get_ipython()
ip.display_formatter.formatters['text/org'] = OrgFormatter()
  • And other minor tweaks.

It is worth mentioning that setting org-babel-ipython-debug to t has a significant impact on performance of evaluation of ipython block. So I always turn it off except when I want to debug the async process.

Since I use scimax with spacemacs so you'll notice some indentation change. sorry about that.

The new function is used to replace `org-in-src-block-p` and other conditions to
determine whether we are on a ipython src-block. It is more light-weight and
causing less performance overhead.
That function is too heavy. Use its light version or org-element-at-point
instead whenever possible.
@jkitchin jkitchin merged commit 79be704 into jkitchin:master Nov 2, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants