Make less assumptions about where `point` is at when inserting results and
about the insertion context by relying only on
`org-babel-where-is-src-block-result` to move `point`. Centralize handling of
`point` to `jupyter-org--do-insert-result`.
* jupyter-org-client.el
(jupyter-org--first-result-context-p): Handle more cases.
(jupyter-org--append-stream-result-p): New function.
(jupyter-org--prepare-append-result): New function, abstracted from
`jupyter-org--insert-result`.
(jupyter-org--normalized-insertion-context): New function.
(jupyter-org--do-insert-result): New function.
(jupyter-org--insert-result): Move the bulk of the work to
`jupyter-org--do-insert-result`.
(jupyter-org--add-result): Use it.
Also consider indentation when inserting results. This was fairly easy to do
and didn't seem to warrant a separate commit.
* jupyter-org-client.el
(jupyter-org--insert-element): Remove. Update all callers.
(jupyter-org-delete-blank-line): New function.
(jupyter-org--delete-element): Use it.
(jupyter-org--stream-context-p): Consider indentation.
(jupyter-org--fixed-width-append): Remove. Update all callers.
(jupyter-org--append-to-fixed-width): Move example block promotion to
`jupyter-org--append-stream-result`.
(jupyter-org--append-to-example-block): New function.
(jupyter-org--append-stream-result): Use it.
(jupyter-org-indent-inserted-region): New macro.
(jupyter-org--insert-result): New method that splits the bulk of the old
function `jupyter-org--append-result` into a more manageable structure. Uses
new macro.
(jupyter-org--append-result): Remove it. Update all callers.
(jupyter-org--add-result): Refactor to consider above changes.
If method arguments are not named it gives rise to errors like
`Args out of range: "", 0`
that originate in `help-function-arglist` when calling `describe-function` on
those methods.
This also fixes an edge case when there is only one blank line after the source
block. The previous version would consider the beginning of the last line of
the code block as the end instead of the beginning of the `#+end_src` line in
that case.
This avoids situations where a paragraph or headline context is deleted
whenever there is no whitespace after the #+RESULTS line and the element after
the #+RESULTS keyword is not a valid result.