Commit graph

367 commits

Author SHA1 Message Date
Nathaniel Nicandro
9dd8e8d9ec Localize functions defined in jupyter-base.el to their call sites
Fixes #137

* jupyter-base.el (jupyter-kernelspec): Un-require.
(jupyter-command, jupyter-locate-python)
(jupyter-runtime-directory): Move to new file `jupyter-env.el`
(jupyter-include-other-output, jupyter-iopub-message-hook)
(jupyter-shell-message-hook)
(jupyter-stdin-message-hook): Move to `jupyter-client.el`
(jupyter-sha256, jupyter-hmac-sha256):
(jupytern-new-uuid): Move to `jupyter-messages.el`. Add declaration of
`jupyter-new-uuid` to account for its removal.
(jupyter-create-connection-info)
(jupyter-write-connection-file): Move to `jupyter-kernel-manager.el`
(jupyter-connect-endpoint, jupyter-connect-channel): Move to `jupyter-channels.el`

* jupyter-channels.el: Accept moved functions.

* jupyter-client.el: Accept moved variables.

* jupyter-kernel-manager.el: Accept moved functions.
(jupyter-env, jupyter-kernelspec): New requires.

* jupyter-kernelspec (jupyter-env): New require.
(jupyter-command): Remove declaration.
(jupyter-read-plist-from-string): New declaration.

* jupyter-messages.el: Accept moved functions.
(hmac-def, json): New requires.

* jupyter-org-extensions.el (jupyter-kernelspec): New require.

* jupyter-repl.el (jupyter-kernelspec): New require.

* jupyter-env.el: New file.

* ob-jupyter.el (jupyter-env, jupyter-kernelspec): New requires.

* test/jupyter-test.el (jupyter-env): New require.
2019-06-29 10:29:55 -05:00
Nathaniel Nicandro
d0518be10c Add jupyter-line-count-greater-p
Speeds up the line count test associated with
`jupyter-eval-short-result-max-lines` by an order of magnitude for somewhat
large strings. The byte compiled versions are not that different.
2019-06-28 20:13:24 -05:00
Nathaniel Nicandro
a4d95aab80 jupyter-handle-message: Drop idle messages less frequently
This accounts for idle messages being dropped before a request's reply message.
In such a case, the request is dropped from the client's request table before
the handlers/callbacks of the request get a chance to handle the reply message.
2019-06-25 09:58:14 -05:00
Nathaniel Nicandro
b7a7c31422 Add jupyter-kernel-managers 2019-06-25 09:35:02 -05:00
Nathaniel Nicandro
c73a597a48 jupyter-wait-until: Suspend timeouts when already waiting 2019-06-22 21:58:00 -05:00
Nathaniel Nicandro
e87f26dee3 jupyter-code-context: Handle all values of parser state 2019-06-13 16:09:18 -05:00
Nathaniel Nicandro
e370769636 jupyter-completion-at-point: Use sit-for
The completion at point functions are called several times in the course of a
single completion attempt so we get multiple chances to receive a completion
result. This means there is no need to wait for it to be received once and for
all on the first time completions are requested.
2019-06-09 15:13:07 -05:00
Nathaniel Nicandro
6289e23c61 Turn jupyter-eval-string into a method
So that client subclasses can provide specialized behavior if needed.

Also adds the function `jupyter-eval-add-callbacks` so that client methods can
more easily obtain the default behavior of `jupyter-eval-string'.
2019-06-08 13:47:13 -05:00
Nathaniel Nicandro
5ea32a70f0 Change License to GPL3 2019-05-31 09:44:39 -05:00
Nathaniel Nicandro
a5e584e498 jupyter-handle-input-request: Suspend timeouts
See #35.
2019-05-30 23:02:40 -05:00
Nathaniel Nicandro
15dc560b14 jupyter-kernel-client: Remove pending-requests slot
There is no need for this slot and is a remnant of an older implementation. A
request is pending if it isn't idle, that is all that we need to know.
2019-05-30 23:02:40 -05:00
Nathaniel Nicandro
4aff8ae975 jupyter-eval-defun: Don't error if no function exists at point 2019-05-21 18:31:14 -05:00
Nathaniel Nicandro
7429755f39 Add jupyter-display-current-buffer-guess-where 2019-05-20 23:14:18 -05:00
jackkamm
1befd70e98 Handle isolated metadata property for HTML results of the R kernel (#115) 2019-05-19 22:40:51 -05:00
Nathaniel Nicandro
d8e3408856 Guard against missing status messages when requesting kernel info 2019-05-13 12:23:02 -05:00
Nathaniel Nicandro
3628cab446 Refactor of jupyter-kernel-manager.el
This refactor implements a new class hierarchy to manage the lifetime of a
Jupyter kernel. The first node in this hierarchy is the
`jupyter-kernel-lifetime` class which defines a set of methods to manage the
lifetime of a kernel. An object that inherits from `jupyter-kernel-lifetime` is
stating that it has an association with a kernel and can be used to manage the
lifetime of the associated kernel.

The `jupyter-meta-kernel` class inherits from `jupyter-kernel-lifetime` and
mainly defines a `spec` slot used to hold the `kernelspec` from which a command
can be constructed to start a kernel and a `session` slot used to hold the
`jupyter-session` object that clients can use to establish communication with a
kernel once its live. Concrete classes that actually launch kernels are
intended to inherit from this class and use its slots.

`jupyter-kernel-process` manages the lifetime of a kernel started as a process
using the function `start-file-process`, `jupyter-command-kernel` calls the
`jupyter kernel` shell command to start a kernel, finally `jupyter-spec-kernel`
uses the `spec` slot to construct a shell command to start a kernel.

A `jupyter-kernel-manager` now consists of a `kernel` slot that holds a
`jupyter-meta-kernel` and a `control-channel` slot and inherits from
`jupyter-kernel-lifetime`. The `jupyter-kernel-lifetime` methods of the manager
just defer to those of `kernel` while also taking into account the
`control-channel`.

* jupyter-base.el (jupyter-write-connection-file): New function.

* jupyter-channel-ioloop.el
(jupyter-channel-ioloop-add-start-channel-event): Remove `sleep-for` call.
The startup message is not so important anymore.

* jupyter-client.el (jupyter-wait-until-startup: New function.

* jupyter-kernel-manager.el (jupyter-kernel-lifetime)
(jupyter-kernel, jupyter-kernel-process, jupyter-command-kernel)
(jupyter-spec-kernel): New classes.
(jupyter-kernel-manager): Inherit from jupyter-kernel-lifetime only and
implement its methods.
(jupyter-kernel-manager--cleanup, jupyter-kernel-managers)
(jupyter-delete-all-kernels, jupyter--kernel-sentinel)
(jupyter--start-kernel): Remove and remove related, their functionality has
been generalized in the new classes.
(jupyter-interrupt-kernel, jupyter-shutdown-kernel)
(jupyter-start-channels, jupyter-start-kernel, jupyter-kernel-alive-p)
(jupyter-kill-kernel): Refactor and implement to use the new class hierarchy.

* test/jupyter-test.el: Refactor tests to account for changes.
(jupyter-write-connect-file, jupyter-command-kernel): New tests.

* jupyter-kernelspec.el (jupyter-guess-kernelspec): New function.
2019-05-09 12:20:27 -05:00
Nathaniel Nicandro
ab79985580 Fix initialize-instance method signature 2019-05-09 10:56:02 -05:00
Nathaniel Nicandro
112769e0c6
Bump version 2019-05-04 03:31:50 -05:00
Nathaniel Nicandro
f744661ac7
jupyter-eval-string: Add callback for :display-data messages 2019-04-11 22:13:39 -05:00
Nathaniel Nicandro
6606fc65e5 Move all debug printing into jupyter-client.el 2019-04-11 20:13:44 -05:00
Nathaniel Nicandro
b2294dceb2 Generalize communication with a kernel
The previous mechanism to communicate with a kernel was too low level from the
perspective of a client. The client interfaced directly with the subprocess
abstraction, `jupyter-ioloop`, and had to handle all "events" that occurred in
the `jupyter-ioloop`, e.g. when a channel was started or stopped. But in
reality such events should not be the concern of a client.

A client should only care about events that are directly related to kernel
messages and not events related to the implementation details of *how*
communication occurs.

This commit abstracts out the way in which a client communicates with its
kernel by introducing a new `jupyter-comm-layer` class. The
`jupyter-comm-layer` class takes care of managing the communication channel
between a kernel and its clients as well as sending events to all registered
clients. This way, clients operate solely at the level of events on the
communication layer. All a client does is register itself to receive events on
the communication layer and send events on the layer.

* jupyter-base.el (jupyter-session-endpoints): New function.

* jupyter-client.el (jupyter-kernel-client): Remove ioloop and channels slots.
  Add kcomm slot.
(initialize-instance): Unconditionally stop channels.
(jupyter-initialize-connection): Change into a method call.
Call `jupyter-initialize-connection` on the `kcomm` slot.
(jupyter-with-client-buffer): Remove stale comment.
(jupyter-send): Call `jupyter-send` on the `kcomm` slot.
(jupyter-ioloop-handler): Remove all method definitions, replace `sent` and
`message` methods with their `jupyter-event-handler` equivalents.
(jupyter-hb-pause, jupyter-hb-unpause, jupyter-hb-beating):
(jupyter-channel-alive-p, jupyter-start-channel, jupyter-stop-channel):
(jupyter-start-channels, jupyter-stop-channels):
Replace with calls to their equivalents using the `kcomm` slot.

* jupyter-comm-layer.el: New file.

* jupyter-kernel-manager (jupyter-make-client): Set a client's `kcomm` slot to
  `jupyter-channel-ioloop-comm`.

* jupyter-messages.el (jupyter-decode-message): Use `list` directly. There
  seemed to be issues when using the new `jupyter-sync-channel-comm` due to
  using quoted lists.

* test/jupyter-test.el: Add `jupyter-comm-layer` test. Update other tests.

* test/test-helper.el: Add `jupyter-comm-layer` mock objects. Update
  `jupyter-echo-client`.
2019-04-11 20:13:44 -05:00
Nathaniel Nicandro
2cfdd6ecfb
Add jupyter-weak-ref(-resolve)? 2019-04-08 12:44:48 -05:00
Nathaniel Nicandro
03a8067e6e
jupyter-handle-message: Only examine :execute-reply of owned requests 2019-03-29 12:29:16 -05:00
Nathaniel Nicandro
d4e24d7870
jupyter-handle-message: Fix update of execution-count 2019-03-29 01:20:39 -05:00
Nathaniel Nicandro
2f18192ae7
Remove redundant :execute-input handlers
The `execution-count` slot of a `jupyter-kernel-client` is now updated higher
up in the message handling process which makes these handlers unnecessary.
2019-03-25 13:19:02 -05:00
Nathaniel Nicandro
a6e476a624
Update a client's execution-count slot on an :execute_input message 2019-03-24 00:11:22 -05:00
Nathaniel Nicandro
8c11fc0615
jupyter-initialize-connection: Refactor 2019-03-23 18:31:35 -05:00
Nathaniel Nicandro
e299a3b3eb
jupyter-code-context (completion): Only consider the deepest nested parenthesis level
This is a better default when considering kernels like Clojupyter.
2019-03-17 20:31:25 -05:00
Nathaniel Nicandro
ffb53244ce jupyter-completion--company-idle-begin: Shorter delay 2019-03-17 02:07:00 -05:00
Nathaniel Nicandro
5e1e30630b jupyter-handle-message: Properly handle :shutdown-reply
A shutdown-reply message received by a request implies that no other messages
will be received for that request since the kernel will shutdown. Also set
`jupyter-request-idle-received-p` to `t` in such cases.
2019-03-17 02:01:00 -05:00
Nathaniel Nicandro
08d974f4db jupyter-requests-pending-p: Fix issues and add test
* Use `hash-table-count`

* Fix the check on determining how many pending requests there are
2019-03-17 02:00:00 -05:00
Nathaniel Nicandro
89ab86ca18
jupyter-eval-string: Don't message error when traceback is being shown 2019-03-16 16:34:18 -05:00
Nathaniel Nicandro
4f168bfc47 jupyter-handle-message: Always handle a startup message 2019-03-14 19:57:00 -05:00
Nathaniel Nicandro
1cc29e2ba0 Add jupyter-requests-pending-p 2019-03-14 19:56:00 -05:00
Nathaniel Nicandro
83af335166
Bump version 2019-03-14 09:29:11 -05:00
Nathaniel Nicandro
6a81470be9
jupyter-eval-short-result-display-function: Don't fail when result has '%' characters 2019-03-14 09:16:44 -05:00
Nathaniel Nicandro
662e983612
Don't require subr-x at runtime 2019-03-14 09:16:44 -05:00
Nathaniel Nicandro
744e27e945
jupyter-eval-string: Don't inhibit :input-request handler
See #35.
2019-03-12 18:35:44 -05:00
Nathaniel Nicandro
fbbef48bee
jupyter-completion-at-point: Handle edge case
Some kernels (e.g. IPython) do not send a `:complete-reply` when the
`:complete-request` is empty, handle this case.
2019-03-07 23:16:37 -06:00
Nathaniel Nicandro
6894a73d57
Cleanup stale comments 2019-03-07 22:51:25 -06:00
Nathaniel Nicandro
581aab10b6
jupyter-kernel-language: Change return value to be a symbol
This avoids interning a string for every method dispatch using the
jupyter-lang method specializer.
2019-03-07 22:51:25 -06:00
Nathaniel Nicandro
57e9af3a13
jupyter-handle-message: Update execution-state for any status message 2019-03-02 18:14:49 -06:00
Nathaniel Nicandro
bdc52c485d
Add jupyter-pop-up-frame
Closes #34
2019-03-01 15:52:42 -06:00
Nathaniel Nicandro
484b0934a3 Fix typos 2019-02-17 23:06:00 -06:00
Nathaniel Nicandro
bad068f15b
jupyter--display-eval-result: Prefer markdown if available
If both plain text and markdown are provided, use markdown. IJulia provides
both representations when, e.g. asking for help on a symbol using ? at the
REPL.
2019-02-17 12:45:26 -06:00
Nathaniel Nicandro
249a088e2e
jupyter-handle-input-request: Be more secure when reading passwords 2019-02-17 12:19:16 -06:00
Nathaniel Nicandro
87f1acbf86
jupyter-read-expression: Show the language when prompting 2019-02-16 11:27:44 -06:00
Nathaniel Nicandro
67befbc10c
jupyter-channel-alive-p: Handle an invalid ioloop process 2019-02-14 23:48:51 -06:00
Nathaniel Nicandro
fafdf0d1b2 jupyter-code-context (completion): Larger context inside nested parens 2019-02-14 23:07:00 -06:00
Nathaniel Nicandro
d4969cbfcc CHANGELOG.org: Add function to change version numbers 2019-02-14 23:05:00 -06:00