gregsexton / ob-ipython

org-babel integration with Jupyter for evaluation of (Python by default) code blocks
739 stars 109 forks source link

Non-Python kernel blocks fail on `org-edit-special` and `font-lock-fontify-block` #134

Open dabro opened 6 years ago

dabro commented 6 years ago

This is an awesome project. I tried running Haskell and Elixir kernels with success -- thank you.

Is it possible to get the babel source blocks to behave properly for non-Python kernels? org-src-lang-modes lists ("ipython" . python); I'm not sure if there's a way to put a function there that would lookup the :kernel header param. Or maybe some entirely different approach? org-src.el and ob-core.el seems to handle all the logic that's problematic.

As far as I can tell, org-edit-src-code (what org-edit-special calls) fails when it in-turn calls org-babel-get-src-block-info, which fails on apply #'org-babel-merge-params :

(apply #'org-babel-merge-params
       (if inline org-babel-default-inline-header-args
         org-babel-default-header-args)
       (and (boundp lang-headers) (eval lang-headers t))
       (append
        ;; If DATUM is provided, make sure we get node
        ;; properties applicable to its location within
        ;; the document.
        (org-with-point-at (org-element-property :begin datum)
          (org-babel-params-from-properties lang))
        (mapcar #'org-babel-parse-header-arguments
                (cons (org-element-property :parameters datum)
                      (org-element-property :header datum)))))

The above results in "Wrong type argument: stringp". At first I thought this was because of nils: the append produces

(nil nil ((:session) (:kernel . "haskell") (:results) (:header . "haskell"))).

Those particular nils come from (org-babel-params-from-properties lang), ie (nil nil). However, the same occurs when the block's kernel is python with no issues.

The problem appears in org-babel-merge-params:

(`(:results . ,value)
       (setq results (funcall merge
                  results-exclusive-groups
                  results
                  (split-string
                   (if (stringp value) value (eval value t))))))

but I'm not sure quite where in the function; my elisp-foo isn't sufficient to understand what's going on. The description of the function is

  "Combine all parameter association lists in PLISTS.
Later elements of PLISTS override the values of previous elements.
This takes into account some special considerations for certain
parameters when merging lists."
gregsexton commented 6 years ago

Think this is done now or we've at least made steps toward it.