Commit graph

179 commits

Author SHA1 Message Date
Nathaniel Nicandro
cabb7e022b
Properly handle org element objects when appending results
Any `org-element` that has a type in `org-element-all-objects` does not have a
newline appended to it when converting to a string representation. This commit
ensures that a newline is added wherever necessary for such elements.

Fixes #8
2019-01-10 23:08:27 -06:00
Nathaniel Nicandro
b2368a920c
jupyter-org--clear-request-id: Ensure the correct buffer is current 2019-01-08 20:25:50 -06:00
Nathaniel Nicandro
80ac63598f
jupyter-org-result: Handle ANSI color codes in text/plain results 2018-12-20 17:15:33 -06:00
Nathaniel Nicandro
8add10db86
jupyter-org--append-result: Fix handling of org-element objects
In particular, file link objects. When an object (in the sense of the
`org-element` API) is inserted by `org-element-interpret-data` it does not
insert a newline since objects are entities that can appear inline with a
paragraph. But for our purposes, we need the newline.

Previously we handled this by wrapping `result` in a list with a newline as the
second element before calling `org-element-interpret-data`, but this interfered
with what `jupyter-org-babel-result-p` (called by
`jupyter-org--wrap-result-maybe`) expected as its argument. With this commit,
the result is never wrapped in a list.
2018-12-19 06:54:41 -06:00
Nathaniel Nicandro
f4e2768886
Silence byte compiler 2018-12-12 11:59:28 -06:00
Nathaniel Nicandro
2e12acd8e3
jupyter-org--fixed-width-to-example-block: Use jupyter-org--delete-element 2018-12-10 22:12:24 -06:00
Nathaniel Nicandro
8d009bb0ba
jupyter-org--add-result: Remove special handling of sync results
Results are not added using `jupyter-org--add-result` anymore for sync results.
They are added by the `org-babel` machinery using `:results raw`.
2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
ffd680fa95
Remove duplicated save-restriction 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
689d18ce54
jupyter-code-context: Return the full code block in an org-mode context
Better support for completions in the Jupyter org-mode source blocks

A line context is often insufficient. For example, the Julia kernel will parse
up to the current point and return dictionary keys as completions or method
arguments. Similarly a Python kernel may use Jedi for completion which does
static analysis of the code block to resolve import paths for completion
results.
2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
8fdde6c756
Update some documentation 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
c6efda58b1
jupyter-org-insert-sync-results -> jupyter-org-sync-results
Change the behavior of `jupyter-org-sync-results` to return the org formatted
result string and modify the result parameters in `org-babel-execute:jupyter`
to add the "raw" result parameter so that the result string is directly
inserted into the buffer.

This is to work towards better support for in-lined code blocks.
2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
c5ebd7bcbd
jupyter-org--same-src-block-p: Handle nil markers 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
2dcb16ef72
Add jupyter-org-raw-string, jupyter-org-raw-string-p
This allows for the distinction between raw org syntax and stream results.
2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
13ee746ee9
jupyter-org-goto-error-map: Add documentation 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
9a50c9c9fc
jupyter-org--append-result: Append newlines when inserting objects
This ensures that org-element objects are always returned by the functions like
`jupyter-org-file-link`. Previously functions that returned org objects would
return the object wrapped in a list.
2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
7b7ddea90f
jupyter-org-scalar: Abstract out table conversion 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
fc7004dd16
jupyter-org-scalar: Return org-elements unchanged 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
ec9713c0aa
Add jupyter-org-comment 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
ad738b5803
jupyter-org--element-end-preserve-blanks -> jupyter-org-element-end-before-blanks
Also simplify its definition.
2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
b4d29e8950
Proper usage of org-babel-min-lines-for-block-output 2018-12-10 21:36:35 -06:00
Nathaniel Nicandro
dab4afc4c6
Dynamically update org-babel stream results
Previously stream results would be placed directly inside the RESULTS drawer.
The issue with this is that sometimes the stream results can be represented as
org syntax.

Instead of inserting stream results directly into a RESULTS drawer, insert them
as either fixed-width or example-block org elements depending on
`org-babel-min-lines-for-block-output`. In addition, coalesce all stream
results so that multiple stream messages in succession produces only one
fixed-width or example-block element.
2018-12-10 18:31:33 -06:00
Nathaniel Nicandro
621fe77c62
jupyter-org--append-result: Move buffer cleanup to jupyter-org--wrap-result-maybe
This may still not be the best place to put buffer modifications, but it
"spreads out the logic" a little more and simplifies
`jupyter-org--append-result`.
2018-12-10 18:04:31 -06:00
Nathaniel Nicandro
c218c976e3
jupyter-org--wrap-result-maybe: Use cond 2018-12-10 18:04:31 -06:00
Nathaniel Nicandro
d269f00036
jupyter-org--append-result: Clear the ID at a higher level 2018-12-01 15:06:07 -06:00
Nathaniel Nicandro
df54627f68
jupyter-org-client.el: Add outline sections 2018-12-01 15:06:07 -06:00
Nathaniel Nicandro
0c0547dd95
Add jupyter-normalize-data 2018-12-01 15:06:07 -06:00
Nathaniel Nicandro
669f1716aa Remove unused functions 2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
f735bed7e6 Split out latex handling in jupyter-org-client.el 2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
8e534edad0 Be more intelligent when parsing LaTeX
It seems `org-element-latex-fragment-parser` expects that a latex fragment can
really be parsed because there were false positives when it was called trying
to parse a latex environment such as `\begin{equation*}...\end{equation*}`. It
would consider `\begin{equation*}` as the fragment.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
e378103db1 Add jupyter-org--wrap-result-maybe
This abstracts out some of the work done by `jupyter-org--append-result`
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
ed24a1cb54 Add TODO about stream output 2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
ee00769959 Add jupyter-org-toggle-latex 2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
5555faa785 Remove the status handler for jupyter-org-clients
The work done by the status handler is now done by the execute reply handler.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
3781c07151 Add the jupyter-org-error-location method
This method is to support jumping to the line where an error occurred in a code
block directly from the `org-mode` buffer.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
2ac0a8b621 Do not conform to the semantics of org-babel-insert-result
There was an ugly hack that destructively modified the source block parameters
supplied to the org-babel execute function to make `org-babel-insert-result` do
all of the insertion work. This relied too much on knowing the internals of
that function. I also could never figure out how to insert stream results in a
clean way.

Instead we manually insert the results by taking advantage of the `org-element`
API. Specifically the function `org-element-interpret-data` which takes an org
syntax tree and returns its printed representation. Now the
`jupyter-org-result` method returns either a string or a syntax tree. If the
latter is returned, it is filtered through `org-element-interpret-data` to
obtain the string representation for insertion.

In addition, all source blocks insert results in a RESULTS drawer. This allows
for inserting stream output as raw text in the drawer and allows for a way to
append results since the end of the drawer acts as an insertion point.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
4ad72e4781 Rename jupyter-output-buffer-* to jupyter-display-buffer-*
An output buffer implies output from the kernel, but they are used for more
general purposes other than displaying output form the kernel.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
f534fe16df jupyter-org-result: Wrap markdown results in an export block
This is to be consistent with other results that are wrapped in a block such as
latex results.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
4d494607fd Rework `org-mode' source block completion
Cache the current source block's information so that there is no need to
constantly retrieve it during completion.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
cec69a6d30 Change jupyter- org-mode prefix to jupy-
This is to avoid name clashing with another popular package that uses the same
prefix.
2018-11-24 22:13:28 -06:00
Nathaniel Nicandro
081f329da1 v0.6.0 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
42cc3d3853 Do not use the make- prefix for struct constructors 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
ea56331f85 Privatize some functions
* jupyter-org-client.el (jupyter-org-add-result, jupyter-org-insert-results):
Add double hyphen for `jupyter-org` namespace.
2018-11-16 00:15:51 -06:00
Nathaniel Nicandro
05bcbba42f Remove special handling of python kernel
In Jupyter > 4.3.0, the Python kernel only sends an execute-result.

* jupyter-org-client.el (jupyter-org-result): Do it.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
0a127766f5 Re-organize code
* jupyter-org-client.el (jupyter-org-result): Move :around method of :text/plain
  results near the :text/plain primary method.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
6c16d184b3 jupyter-handle-message: Let bind `jupyter-current-client' when handling messages
This is necessary to allow for the `jupyter-lang' method specializer to work in
contexts other than the REPL buffer, such as in an `org-mode` buffer when
handling `jupyter-org-request' objects.

* jupyter-client.el (jupyter-handle-message): (CLIENT ...) Do it.

* jupyter-org-client.el (jupyter-org-add-result):
Don't let bind `jupyter-current-client`.
Remove CLIENT argument. Update all callers.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
a819067e6c Implement the jupyter-org-result method
This is in replacement of the `jupyter-org-prepare-result` and
`jupyter-org-transform-result`. A single method with both primary and :around
methods is sufficient.

* jupyter-org-client.el (jupyter-org-mime-types): New variable.
(jupyter-org-prepare-and-add-result): Remove.
(jupyter-handle-execute-result, jupyter-handle-display-data):
Do the work previously done by `jupyter-org-prepare-and-add-result`.
Abstract out the python handling to a `jupyter-org-result` method.
(jupyter-org--image-result): Add PARAMS argument.
Move setup done previously in `jupyter-org-prepare-result` to this function.
(jupyter-org-prepare-result): Remove.
Replace with calls to the `jupyter-org-result' method.
(jupyter-org-result): New method.
(text/html) Remove special handling of <img> tags, this was done due to old
versions of the Julia kernel.
(jupyter-org-transform-result): Remove.
Replace with a `jupyter-org-result` :around method.
Remove all callers.

* jupyter-python.el (jupyter-org-transform-result): Remove.
Replace with a `jupyter-org-result` :around method.

* jupyter-tests.el (jupyter-org-result): Add tests.

org-result
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
175a09b3c5 Make jupyter-org-clear-request-id a private function
* jupyter-org-client.el (jupyter-org-clear-request-id): Rename to
  `jupyter-org--clear-request-id`.
All callers changed.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
f64a84c923 Simplify setting of :silent slot for `jupyter-org-request' objects
* jupyter-org-client.el (jupyter-generate-request): Do it.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
75a08c26d0 Implement jupyter-insert method
The goal of this method is to act as a single entry point for insertion of
kernel results in any context. One would simply add another method to handle a
specific context.

* jupyter-base.el (jupyter-mime-types):
(jupyter-nongraphic-mime-types): New variables that give mime-types that can be
handled.
(jupyter-insert): New method for dispatching to code that inserts mimetype
representations in the current buffer.

* jupyter-mime.el: New file.
(jupyter-display-ids):
(jupyter-handle-control-codes):
(jupyter-fontify-buffers):
(jupyter-get-fontify-buffer):
(jupyter-fixup-font-lock-properties):
(jupyter-add-font-lock-properties):
(jupyter-fontify-according-to-mode):
(jupyter-insert-html):
(jupyter-markdown-mouse-map):
(juputer-markdown-follow-link-at-point):
(jupyter-insert-markdown):
(jupyter-insert-latex):
(jupyter-insert-ansi-coded-text): Moved from jupyter-repl.el, replaced
`jupyter-repl-` prefix with `jupyter-`.
(jupyter--shr-put-image): Ditto. Also add `shr-` prefix.
(jupyter--delete-javascript-tags): Ditto. Also mark as private functions.
(jupyter-insert-image): Ditto. Also mark as a public function.
(jupyter-insert): (DISPLAY-ID ...) Moved from jupyter-repl.el. Was
`jupyter-repl-insert-data-with-id`.
(jupyter-with-control-code-handling):
(jupyter-markdown-follow-link): Moved from jupyter-repl.el
(jupyter-insert): Implement methods to do the work previously done by
`jupyter-repl-insert-data`.

* jupyter-repl.el (jupyter-repl-graphic-mimetypes): Moved to jupyter-base.el,
 inverted and renamed to `jupyter-nongraphic-mime-types`.
(jupyter-repl-graphic-data-p): Remove unused function.
(jupyter-repl-insert-data): Remove, replace calls with `jupyter-insert`.
(jupyter-repl-add-font-lock-properties):
(jupyter-repl-fixup-font-lock-properties):
(jupyter-repl-get-fontify-buffer):
(jupyter-repl-fontify-according-to-mode):
(jupyter-repl-delete-javascript-tags):
(jupyter-repl-put-image):
(jupyter-repl-insert-html):
(jupyter-repl-markdown-mouse-map):
(jupyter-repl-markdown-follow-link-at-point):
(jupyter-repl-insert-markdown):
(jupyter-repl-insert-latex):
(jupyter-repl--insert-image): Moved to jupyter-mime.el, which see.
(jupyter-repl-insert-data-with-id): Ditto. Changed to a `jupyter-insert` method
dispatched on a string argument.
(jupyter-repl-insert-ansi-coded-text): Ditto. Replace calls with
`jupyter-insert-ansi-coded-text`.
(jupyter-with-control-code-handling):
(jupyter-markdown-follow-link): Moved to jupyter-mime.el.

* jupyter-org-client.el (jupyter-handle-error): Replace
  `jupyter-repl-insert-ansi-coded-text` with `jupyter-insert-ansi-coded-text`.

* jupyter-tests.el (jupyter-insert): Add tests for `jupyter-insert`
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
11dda1b9ab Prioritize images in org-mode buffers 2018-11-09 09:02:28 -06:00