diff --git a/ob-ipython.el b/ob-ipython.el index 043fb9a..4dd9129 100644 --- a/ob-ipython.el +++ b/ob-ipython.el @@ -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) @@ -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))))) @@ -593,6 +597,7 @@ 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))) @@ -600,10 +605,11 @@ This function is called by `org-babel-execute-src-block'." (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) @@ -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)))) @@ -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"))