Commit graph

47 commits

Author SHA1 Message Date
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
Nathaniel Nicandro
88c126ffe1 jupyter-org-prepare-result: Use the right JPEG mimetype.
* jupyter-org-client.el (jupyter-org-prepare-result): Replace :image/jpg with :image/jpeg.
2018-11-08 21:30:32 -06:00
Nathaniel Nicandro
0095367796 Remove usage of old function 2018-11-07 14:23:54 -06:00
Nathaniel Nicandro
f5278cf027 Remove usage of old macro 2018-11-07 14:23:48 -06:00
Nathaniel Nicandro
890f5ab3cb Silence byte compiler
* Declare undeclared external functions

* Add ext: prefix to filename of external packages that may not be present on
  every system

* Remove `company-grab-symbol-cons` function declaration since this function is
  no longer used.
2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
8896e88476 Move language support definitions to their own files
* Define `jupyter-load-language-support` which takes a client and loads the
  language support definitions of the client's kernel language.

* Call `jupyter-load-language-support` when initializing a REPL buffer in
  `jupyter-repl-mode`. Note this also takes care of loading the kernel support
  for a `jupyter-org-client' since a REPL buffer is setup before evaluating any
  `org-mode` source code blocks.

* Move language specific methods to their own files named `jupyter-LANGUAGE.el`
2018-10-25 23:59:46 -05:00
Nathaniel Nicandro
5046ac91b4 jupyter-code-context: Only send the line context for org-mode completion requests
Sending the entire code block on every completion request seems like overkill.
2018-10-25 23:59:46 -05:00
Nathaniel Nicandro
fb3dd1eebf jupyter-code-context: Only send the current line context for a jupyter-org-client
Previously the entire code cell was sent, but this can be an issue for large
code cells.
2018-10-25 23:17:28 -05:00
Nathaniel Nicandro
948fa6adfc Rename jupyter-with-doc-buffer to jupyter-repl-with-doc-buffer
Also rename `jupyter-get-doc-buffer` to `jupyter-repl-get-special-buffer`
2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
a9246fcecb Rename with-jupyter-* to jupyter-with
Ensure that all functions and macros have the same
pseudo-namespace
2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
394a82a5c2 Update note on injecting render parameters for displaying org-mode results 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
da6587f5f6 Only modify the result parameters if needed in jupyter-org-add-result 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
1198965d57 Documentation changes 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
6e59813dc4 Add to CAPF for code block completion when org-mode is enabled 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
90f2878617 Fix code beginning position of completion context for org-mode source blocks 2018-10-25 23:17:24 -05:00
Nathaniel Nicandro
19abd9a5c6 Define and use the jupyter-lang method context specializer
* Define the `jupyter-lang` method context specializer that
  specializes against the kernel language of
  `jupyter-current-client`

* Remove the kernel support API

* Replace the kernel support API with methods that can be
  specialized using the `jupyter-lang` context specializer.
2018-10-25 23:17:09 -05:00
Nathaniel Nicandro
c0c9d8dd70 Ensure the return value of jupyter-org-prepare-result has a non-nil car and cdr 2018-10-25 23:07:46 -05:00
Nathaniel Nicandro
a8231db79b Rename jupyter-repl-current-client to jupyter-current-client
Also move `jupyter-current-client` to `jupyter-client.el`
2018-10-25 23:07:46 -05:00
Nathaniel Nicandro
8bb43e6c68 Rename jupyter-repl-language to jupyter-kernel-language
Also move `jupyter-kernel-language` to `jupyter-client.el`
2018-10-25 23:07:46 -05:00
Nathaniel Nicandro
d1588b2fd9 Define jupyter-completion-prefix as a method to use it in different contexts 2018-10-25 23:07:04 -05:00
Nathaniel Nicandro
44d1af31bb Generalize retrieving the code context
* Rename `jupyter-code-context-at-point` to `jupyter-code-context`

* Use `cl-defmethod` and specializers to handle the
  different kinds of contexts

* Move the newly defined code context methods to their
  appropriate locations
2018-10-25 22:57:33 -05:00
Nathaniel Nicandro
c070f2d04d Update documentation and comments 2018-10-25 22:57:23 -05:00
Nathaniel Nicandro
deda7edea1 Silence byte compiler 2018-10-25 22:10:16 -05:00
Nathaniel Nicandro
414d124886 Rename jupyter-org--handle-data to jupyter-org-prepare-and-add-result 2018-10-25 22:10:16 -05:00
Nathaniel Nicandro
9c99e5f2f9 Add jupyter-org-file-header-arg-p 2018-10-25 22:10:16 -05:00
Nathaniel Nicandro
23acb30759 Refactor jupyter-org-clear-request-id to use the jupyter-org-request fields 2018-10-25 22:10:16 -05:00
Nathaniel Nicandro
30db9a8b2b Handle kernel differences in message sequence during execution 2018-10-16 13:55:57 -05:00
Nathaniel Nicandro
a0a9ac2910 Update documentation, purge stale comments 2018-10-16 13:55:50 -05:00
Nathaniel Nicandro
de9f85cc2e Update documentation, cleanup comments
* Remove implementation details in documentation strings

* Canonicalize documentation of functions which perform similar operations.
2018-10-16 13:55:30 -05:00
Nathaniel Nicandro
55449c1d6a Introduce jupyter-org-client
- A `jupyter-org-client` is a subclass of a `jupyter-repl-client` and replaces
  the use of callbacks in `org-babel-execute:jupyter` to handle the insertion
  of code block results in an `org-mode` buffer. `ob-jupyter.el` now only
  contains the integration with `org-babel` and all integration with
  `emcacs-jupyter` is placed in `jupyter-org-client.el`

- Introduce `jupyter-org-request`, which inherits all of the field of a
  `jupyter-request` and adds the fields necessary for keeping track of the
  source code block information a request was generated from during the
  lifetime of the request.
2018-10-16 13:55:30 -05:00