From 1bcc3b87c545354694c0257c2df3db8794937976 Mon Sep 17 00:00:00 2001 From: John Miller Date: Tue, 19 Sep 2017 13:08:13 -0500 Subject: [PATCH] ob-ein: Tap into ein autocompletion for org source edit buffers. Will try to use ein completion backend configured by user when editing ein source blocks in org. Also slightly more robust inspecting in ein_inspector.py --- lisp/ein_inspector.py | 13 ++++++++----- lisp/ob-ein.el | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lisp/ein_inspector.py b/lisp/ein_inspector.py index 48a2f79..84dddaf 100644 --- a/lisp/ein_inspector.py +++ b/lisp/ein_inspector.py @@ -32,9 +32,12 @@ def generate_inspector_data(obj_str, globals, locals): else: odata['doc'] = inspect.getdoc(obj) odata['type'], odata['repr'] = determine_object_type(obj) - odata['source_file'] = inspect.getsourcefile(obj) - odata['source_lines'] = inspect.getsourcelines(obj) - + try: + odata['source_file'] = inspect.getsourcefile(obj) + odata['source_lines'] = inspect.getsourcelines(obj) + except: + odata['source_file'] = None + odata['source_lines'] = None print(json.dumps(odata)) return odata @@ -78,6 +81,6 @@ def determine_object_type(obj): elif inspect.ismemberdescriptor(obj): return 'Member Descriptor', obj.__str__() elif inspect.isbuiltin(obj): - return type(obj), obj.__str__() + return str(type(obj)), obj.__str__() else: - return type(obj), obj.__str__() + return str(type(obj)), obj.__str__() diff --git a/lisp/ob-ein.el b/lisp/ob-ein.el index b481b67..1c1e588 100644 --- a/lisp/ob-ein.el +++ b/lisp/ob-ein.el @@ -130,6 +130,20 @@ jupyter kernels. (slot-value cell 'traceback)))) (org-babel-ein-process-outputs (slot-value cell 'outputs) processed-params))))) + +(defun org-babel-edit-prep:ein (babel-info) + "Set up source code completion for editing and EIN source block." + (let ((session (assoc :session (third babel-info)))) + (case ein:completion-backend + (ein:use-ac-backend (ein:complete-on-dot-install python-mode-map 'ein:notebook-complete-dot) + (auto-complete-mode +1)) + (ein:use-ac-jedi-backend (ein:jedi-complete-on-dot-install python-mode-map) + (auto-complete-mode +1)) + (ein:use-company-backend (company-mode +1)) + (ein:use-company-jedi-backend (warn "Support for jedi+company currently not implemented. Defaulting to just company-mode") + (company-mode +1)) + (t nil)))) + ;; This function should be used to assign any variables in params in ;; the context of the session environment. (defun org-babel-prep-session:ein (session params)