Commit graph

1577 commits

Author SHA1 Message Date
Nathaniel Nicandro
bf5589e428 Avoid use of jupyter-ioloop-wait-until
* jupyter-channel-ioloop-comm.el (jupyter-stop-channel)
(jupyter-start-channel): Do it.

See https://github.com/dzop/emacs-jupyter/issues/148#issuecomment-511219046

In reality `jupyter-ioloop-wait-until` should be fixed to handle the case of
multiple events coming in before checking the waiting condition, but in this
case we can just check the liveness of the channels.
2019-07-14 17:20:41 -05:00
Nathaniel Nicandro
abc029fd41 jupyter-get: Return nil on unbound variables, make setf-able
* jupyter-client.el (jupyter-get): Do it.
2019-07-14 17:20:41 -05:00
Nathaniel Nicandro
653f934bfc Add jupyter-org-(next|previous)-busy-src-block
* jupyter-org-extensions.el (jupyter-org-next-busy-src-block)
(jupyter-org-previous-busy-src-block): Do it.
(jupyter-org-hydra/body): Add N and P bindings.
2019-07-14 17:20:41 -05:00
Nathaniel Nicandro
1b1a55ef3f Add jupyter-org-request-at-point
* jupyter-org-client.el (jupyter-org-request-at-point): Do it.
(org-babel-jupyter-src-block-session): New declare.

* ob-jupyter.el (org-babel-jupyter-session-clients): Add doc about keys.

* test/jupyter-test.el (jupyter-org-request-at-point): New test.
2019-07-14 17:20:41 -05:00
Nathaniel Nicandro
259e8c5b86 Add jupyter-map-pending-requests
* jupyter-client.el (jupyter-map-pending-requests): Do it.

* test/jupyter-test.el (jupyter-map-pending-requests): New test.
2019-07-14 17:20:41 -05:00
Nathaniel Nicandro
1e9da5753d Add jupyter-org-interrupt-kernel
* jupyter-org-extensions.el (jupyter-org-interrupt-kernel): Do it.
(jupyter-org-hydra/body): Add i binding.

* jupyter-repl.el (jupyter-repl-interrupt-kernel): Clarify error message.
2019-07-14 17:20:18 -05:00
Nathaniel Nicandro
df6651a1f1 jupyter-org-result: More informative error
* jupyter-org-client.el (jupyter-org-result): Do it.
2019-07-14 17:03:38 -05:00
Yevgnen
c5c2c84a0d Add jupyter-org-adjust-image-size (#147) 2019-07-14 12:44:31 -05:00
Nathaniel Nicandro
7c1689e33d jupyter-org-client.el: Don't assume non-empty strings 2019-07-11 16:40:37 -05:00
Nathaniel Nicandro
e084842242 jupyter-org-insert-src-block: Don't move past an inlinetask 2019-07-10 19:24:06 -05:00
Nathaniel Nicandro
642b0ef592 jupyter-org-insert-src-block: Be aware of a src-block's results
When `point` is between a src-block and its result with only whitespace
separating the end of a src-block and the beginning of its results, insert a
new src-block after the result.
2019-07-10 17:28:58 -05:00
Nathaniel Nicandro
08a4723c0b jupyter-widgets-on-message: Fix wrong argument to jupyter-send 2019-07-10 12:02:13 -05:00
Nathaniel Nicandro
d5492c54fb jupyter-runtime-directory: Use an existing directory
Set `default-directory` to one that should exist otherwise tests fail on
Appveyor.
2019-07-09 13:50:27 -05:00
Nathaniel Nicandro
31b551bdc1 org-babel-jupyter--run-repl: Make language aliases for remote kernelspecs 2019-07-09 13:50:20 -05:00
Nathaniel Nicandro
0f01a2a2ed ob-jupyter.el: Don't make language aliases at load time 2019-07-09 13:47:17 -05:00
Nathaniel Nicandro
fb0317acdd Raise errors when jupyter-command returns nil
* jupyter-env.el (jupyter-runtime-directory): Do it.

* jupyter-kernelspec.el (jupyter-available-kernelspecs): Do it.
2019-07-09 13:47:17 -05:00
Nathaniel Nicandro
7b78ca7013 jupyter-runtime-directory: Don't call shell commands at load time
* jupyter-env.el (jupyter-runtime-directory): Remove custom status.
New function definition.

* jupyter-kernel-manager.el (jupyter-write-connection-file):
Use new function.

* ob-jupyter.el (org-babel-jupyter--run-repl):
Remove setting of `jupyter-runtime-directory`.

* test/jupyter-test.el (jupyter-runtime-directory): New test.
2019-07-08 20:23:23 -05:00
Nathaniel Nicandro
4f944d311c jupyter-send (jupyter-ioloop): Fix placement of setq 2019-07-08 17:27:29 -05:00
Nathaniel Nicandro
4daa09bb15 jupyter-send (jupyter-ioloop): Don't create a temporary buffer on every send 2019-07-08 16:56:36 -05:00
Nathaniel Nicandro
02a0b470d9 jupyter-ioloop: Fix for subprocess stdin buffering issue 2019-07-08 16:56:28 -05:00
Nathaniel Nicandro
909cdf3dd7 jupyter-org-insert-src-block: Add blank lines where appropriate 2019-07-01 11:49:17 -05:00
Nathaniel Nicandro
23a692d0b4 jupyter-completion-prefix (julia): Don't keep : prefix on non-symbol looking prefixes 2019-07-01 11:49:17 -05:00
Nathaniel Nicandro
6f0686e186 jupyter-kernel-info: Increase timeout again
Needed much more often for the IJulia kernel when starting it via the notebook
support landing soon.
2019-07-01 11:46:57 -05:00
Nathaniel Nicandro
f5d852dc6d Fix macro hygiene issues 2019-06-30 12:36:41 -05:00
Nathaniel Nicandro
4c3168d53f Add jupyter-server-mode-set-client
This is an attempt at associating a REPL client with a buffer which was created
by emacsclient.
2019-06-30 12:36:41 -05:00
Nathaniel Nicandro
8f9ec15af0 Add jupyter-org-table-string 2019-06-30 12:22:26 -05:00
Nathaniel Nicandro
aedd0d41d6 Update README 2019-06-30 12:22:26 -05:00
Nathaniel Nicandro
7bce62e2ae jupyter-create-connection-info -> jupyter-local-tcp-conn-info
Also use `jupyter-available-local-ports` to get ports for use.
2019-06-30 12:22:26 -05:00
Nathaniel Nicandro
8fc5f0bbee Make jupyter-channel-ioloop independent of zmq
This change localizes all `zmq` related functionality to `jupyter-ioloop` and
`jupyter-zmq-*` files.

* jupyter-channel-ioloop-comm.el: Add better commentary.
(jupyter-base): Require.
(jupyter-channel-ioloop-comm): Add `ioloop-class` slot
(initialize-instance [jupyter-channel-ioloop-comm]): Use it.

* jupyter-channel-ioloop.el (jupyter-base, jupyter-zmq-channel): Un-require.
(jupyter-ioloop-session, jupyter-ioloop-channels):
Rename to `jupyter-channel-ioloop-session` `jupyter-channel-ioloop-channels` and
update all callers.
(jupyter-channel-ioloop): Make into an abstract class.
(initialize-instance [jupyter-channel-ioloop]): Re-add
`jupyter-channel-ioloop-add-send-event`. Don't add to
`jupyter-ioloop-post-hook`.
(jupyter-channel-ioloop-recv-messages): Remove.
(jupyter-channel-ioloop--set-session, jupyter-ioloop-start)
(jupyter-channel-ioloop-add-send-event): Doc changes.
(jupyter-channel-ioloop-add-start-channel-event)
(jupyter-channel-ioloop-add-stop-channel-event):
Don't add/remove from the `jupyter-ioloop-poller`.
Now expected to be handled in the `jupyter-channel` subclass.
Update documentation. In addition, for the start-channel event,
do not attempt to add a channel if one doesn't already exist.

* jupyter-ioloop.el
(jupyter-ioloop-add-teardown):
Remove mention of `jupyter-channel-ioloop` behavior.
(jupyter-ioloop-add-arg-type): Update example variable.
(jupyter-ioloop-environment-p): New function.

* jupyter-kernel-manager.el (jupyter-channel): Require.
(jupyter-make-client): Require and use `jupyter-zmq-channel-ioloop`.
(jupyter-start-channels): Use `make-instance`.
(jupyter-interrupt-kernel): Remove `condition-case`. Not needed since
preventing socket blocking is now handled by `jupyter-recv`.

* jupyter-repl.el
(jupyter-connect-repl): Require and use `jupyter-zmq-channel-ioloop`.

* jupyter-zmq-channel-ioloop.el: New file.

* jupyter-zmq-channel.el (jupyter-ioloop-poller-remove)
(jupyter-ioloop-poller-add): New declares.
(jupyter-start-channel):
Add to `jupyter-ioloop-poller` when in `jupyter-ioloop-environment-p`.
(jupyter-stop-channel):
Only disconnect the socket from its endpoint instead of closing it, leave that
up to garbage collection.
Remove from `jupyter-ioloop-poller` when in `jupyter-ioloop-environment-p`.
(jupyter-recv): Handle non-blocking.

* test/jupyter-test.el
(jupyter-zmq-channel): Use non-blocking `zmq-send` since socket is no longer
closed when calling `jupyter-stop-channel`.
(jupyter-ioloop-test-eval-ioloop): Rename to `jupyter-test-ioloop-eval-event`,
update all callers, and move to `test/test-helper.el`.
(jupyter-channel-ioloop-send-event, jupyter-channel-ioloop-stop-channel-event)
(jupyter-channel-ioloop-start-channel-event): Fix tests for variable name
changes. Use `jupyter-test-channel-ioloop`. Update `jupyter-ioloop-poller`,
addition/removal from poller is now done in the `jupyter-channel` subclass by
checking `jupyter-ioloop-environment-p`.

* test/test-helper.el (jupyter-zmq-channel-ioloop): Require.
(initialize-instance [jupyter-echo-client]): Use it.
(jupyter-test-channel-ioloop): New macro.
(jupyter-test-ioloop-eval-event): New function.
2019-06-30 12:22:26 -05:00
Nathaniel Nicandro
dca8dac257 Mention behavior of jupyter-ioloop-poller-(add|remove) in doc strings 2019-06-30 12:22:16 -05:00
Nathaniel Nicandro
58b715a4e8 Break up jupyter-channels.el to further decouple zmq
* jupyter-channel-ioloop.el (jupyter-zmq-channel): Require.
(jupyter-channel-ioloop-add-start-channel-event): `sync` -> `zmq`

* jupyter-comm-layer (jupyter-comm--channel): Moved from `jupyter-channels.el`.

* jupyter-kernel-manager.el: `sync` -> `zmq`

* jupyter-zmq-channel-comm.el: New file.

* jupyter-channels.el: Mostly renamed to jupyter-zmq-channel.el. The
`jupyter-channel` class was moved to `jupyter-channel.el`. All that remains are
those classes dependent on `zmq`.

* test/jupyter-test.el: `sync` -> `zmq` where appropriate.

Extract `jupyter-channel` class from `jupyter-zmq-channel.el` into its own file
2019-06-29 14:11:04 -05:00
Nathaniel Nicandro
b40b7de837 Do not depend strongly on zmq
Having the `jupyter-comm-layer` abstraction means we do not need to do so.

* jupyter-base.el (zmq): Un-require.
(jupyter-socket-types): Move to `jupyter-channels.el`.
(jupyter-session): Don't mention zmq in doc string.
(jupyter-available-local-ports, jupyter-make-ssh-tunnel): New functions.
(jupyter-tunnel-connection): Use them.

* jupyter-channel-ioloop-comm.el: New file.

* jupyter-channels.el (jupyter-messages): Un-require.
(jupyter-comm-layer, zmq): New requires.
(jupyter-socket-types): Moved from `jupyter-base.el`.
(jupyter-send, jupyter-recv):
Implementations for `jupyter-session` moved from `jupyter-messages.el`.
(jupyter-sync-channel-comm): `jupyter-comm-layer` implementation for
`jupyter-sync-channel` objects moved from `jupyter-comm-layer.el`.

* jupyter-comm-layer.el (jupyter-channel-ioloop): Un-require.
(jupyter-sync-channel-comm): Move implementation to `jupyter-channels.el`.
(jupyter-ioloop-comm): Move implementation to new file `jupyter-ioloop-comm.el`.
(jupyter-channel-ioloop-comm):
Move implementation to new file `jupyter-channel-ioloop-comm.el`.

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

* jupyter-ioloop.el (zmq): Require.

* jupyter-kernel-manager.el
(jupyter-make-client): Ensure `jupyter-channel-ioloop-comm` is required.

* jupyter-messages.el (jupyter-send)
(jupyter-recv): Moved to `jupyter-channels.el`

* jupyter-repl.el
(jupyter-connect-repl): Ensure `jupyter-channel-ioloop-comm` is required.

* test/jupyter-test.el (jupyter-available-local-ports): New test.

* test/test-helper.el (jupyter-channel-ioloop-comm): New require.
2019-06-29 10:29:55 -05:00
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
030c3e2d0c Fix issues with undo in the REPL
Related to let binding `buffer-undo-list` improperly and making text read-only
when it shouldn't be.

Fixes #139

* jupyter-repl.el (jupyter-repl-with-single-undo)
(jupyter-repl-inhibit-undo-when): New macros.
(jupyter-repl-insert): Inhibit undo only when insertions are `read-only`
(jupyter-repl-insert-prompt): Don't make continuation prompts `read-only`
(jupyter-repl-replace-cell-code): Allow the argument to be a `buffer`. Use
`replace-buffer-contents` in this case. Avoids unnecessary undo information.
(jupyter-handle-is-complete-reply): Don't insert a `read-only` newline on
incomplete cell code.
(jupyter-repl-indent-line): Pass buffer to `jupyter-repl-replace-cell-code`
(jupyter-repl-insert-continuation-prompts): Don't inhibit undo

* test/jupyter-test.el (jupyter-repl-undo): Add more tests.
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
95b985e8d6 jupyter-repl-clear-cells: Move to cell code beginning 2019-06-28 20:13:24 -05:00
Jamie Forth
05d01ee1e5 jupyter-org-client.el: Check for tables when mime type is text/org
This allows for better integration with backends that can generate
org-format tables.
2019-06-28 20:12:52 -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
25ff5dd871 jupyter-org-client: Remove unnecessary block-params slot 2019-06-23 16:11:27 -05:00
Nathaniel Nicandro
19bcf2bba2 jupyter-hb--send-ping: Handle a closed socket 2019-06-23 16:11:27 -05:00
Nathaniel Nicandro
5bf04d24de jupyter-interrupt-kernel: Fix typo 2019-06-22 22:02:00 -05:00
Nathaniel Nicandro
d7b8719126 jupyter-ioloop--make-filter: Handle important events always
Previously events like start or quit would only get handled if
`jupyter-ioloop-handler` was called, but those events need to get handled
regardless.
2019-06-22 22:01:00 -05:00
Nathaniel Nicandro
34a4c8edf2 .travis.yml: Explicitly request trusty distribution
GCC in Xenial is buggy.
2019-06-22 22:00:00 -05:00
Nathaniel Nicandro
897183d11a Show Jupyter version info during CI tests 2019-06-22 21:59:00 -05:00
Nathaniel Nicandro
c73a597a48 jupyter-wait-until: Suspend timeouts when already waiting 2019-06-22 21:58:00 -05:00
Nathaniel Nicandro
44c3c1a9ea Add jupyter-comm-id
Used to get an identification string of the connection that a kernel client is
using.
2019-06-22 21:57:00 -05:00
Nathaniel Nicandro
1e84b42f42 Silence byte compile warning 2019-06-22 21:56:00 -05:00
Nathaniel Nicandro
3580228b6b jupyter-ioloop-post-hook: Adhere to the documentation 2019-06-22 21:55:00 -05:00
Nathaniel Nicandro
f023339a85 jupyter-org-insert-src-block: Respect the element under point 2019-06-22 21:54:00 -05:00