Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions ob-ipython.el
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
"Directory where resources (e.g images) are stored so that they
can be displayed.")

(defcustom ob-ipython-suppress-execution-count nil
"If non-nil do not show the execution count in output."
:group 'ob-ipython)

;; utils

(defun ob-ipython--write-string-to-file (file string)
Expand Down Expand Up @@ -313,7 +317,7 @@ a new kernel will be started."

(defun ob-ipython--maybe-run-async ()
(when (not (ob-ipython--running-p))
(when-let (val (ob-ipython--dequeue 'ob-ipython--async-queue))
(-when-let (val (ob-ipython--dequeue 'ob-ipython--async-queue))
(cl-destructuring-bind (code name callback args) val
(ob-ipython--run-async code name callback args)))))

Expand Down Expand Up @@ -593,17 +597,19 @@ This function is called by `org-babel-execute-src-block'."
(let* ((file (cdr (assoc :ipyfile params)))
(session (cdr (assoc :session params)))
(result-type (cdr (assoc :result-type params)))
(result-params (cdr (assoc :result-params params)))
(sentinel (ipython--async-gen-sentinel)))
(ob-ipython--create-kernel (ob-ipython--normalize-session session)
(cdr (assoc :kernel params)))
(ob-ipython--execute-request-async
(org-babel-expand-body:generic (encode-coding-string body 'utf-8)
params (org-babel-variable-assignments:python params))
(ob-ipython--normalize-session session)
(lambda (ret sentinel buffer file result-type)
(let ((replacement (ob-ipython--process-response ret file result-type)))
(ipython--async-replace-sentinel sentinel buffer replacement)))
(list sentinel (current-buffer) file result-type))
(lambda (ret sentinel buffer file result-type result-params)
(unless (member "silent" result-params)
(let ((replacement (ob-ipython--process-response ret file result-type)))
(ipython--async-replace-sentinel sentinel buffer replacement))))
(list sentinel (current-buffer) file result-type result-params))
(format "%s - %s" (length ob-ipython--async-queue) sentinel)))

(defun ob-ipython--execute-sync (body params)
Expand All @@ -626,7 +632,9 @@ This function is called by `org-babel-execute-src-block'."
output
(ob-ipython--output output nil)
(s-concat
(format "# Out[%d]:\n" (cdr (assoc :exec-count ret)))
(if ob-ipython-suppress-execution-count
""
(format "# Out[%d]:\n" (cdr (assoc :exec-count ret))))
(s-join "\n" (->> (-map (-partial 'ob-ipython--render file)
(list (cdr (assoc :value result))
(cdr (assoc :display result))))
Expand Down Expand Up @@ -656,7 +664,7 @@ This function is called by `org-babel-execute-src-block'."
(let ((lines (s-lines value)))
(if (cdr lines)
(->> lines
(-map 's-trim)
(-map 's-trim-right)
(s-join "\n ")
(s-concat " ")
(format "#+BEGIN_EXAMPLE\n%s\n#+END_EXAMPLE"))
Expand Down