Commit graph

104 commits

Author SHA1 Message Date
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
74a6cfd541 Add test for jupyter-org-define-key 2019-06-13 10:46:19 -05:00
Nathaniel Nicandro
f3b94bab39 jupyter-start-kernel: Do nothing if kernel is already alive 2019-06-12 23:03:05 -05:00
Nathaniel Nicandro
23ad05fd64 jupyter-kill-kernel: Don't unbind the session slot of a kernel
Not really sure why this was done in the first place, but a kernel can be
forcibly killed and then asked to started up again, e.g. when restarting the
kernel.
2019-06-12 23:02:45 -05:00
Nathaniel Nicandro
e7d80cf399 Add test for #126 2019-06-12 21:10:26 -05:00
Nathaniel Nicandro
fda5f0b414 jupyter-org-font-lock-ansi-escapes: Fix regexp for fixed-width blocks 2019-06-11 22:12:58 -05:00
Nathaniel Nicandro
9f15db7133 jupyter-org--append-to-example-block: Fix edge case
Fix the case when appending to a line without inserting a newline and adding
indentation.

Also add tests for `jupyter-org--append-to-example-block`
2019-06-11 22:12:58 -05:00
Nathaniel Nicandro
66f806f478 Add test for jupyter-org-indent-inserted-region 2019-06-11 22:12:58 -05:00
Nathaniel Nicandro
878b323594 jupyter-org--append-to-fixed-width: Fix edge case 2019-06-11 20:17:06 -05:00
Nathaniel Nicandro
40ee1ac8b9 Add new customizable variable jupyter-repl-echo-eval-p
Closes #71
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
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
0b49588096 jupyter-disconnect-client: Don't close comm by default
But do so for `jupyter-channel-ioloop-comm` as only a single client is meant to
be connected anyways.
2019-05-30 23:02:40 -05:00
Nathaniel Nicandro
24b6dbadac Add test for `jupyter-locate-python' 2019-05-20 18:17:51 -05:00
Nathaniel Nicandro
edf3097b04 org-babel-jupyter-override-src-block: Be more robust
Fixes #118
2019-05-20 14:52:26 -05:00
Nathaniel Nicandro
d7757d6de4 jupyter-repl-history--rotate: Handle an empty history 2019-05-19 19:34:07 -05:00
poppyschmo
b7b0162572 Add prev/next-matching REPL-input-history commands (#108) 2019-05-19 19:13:14 -05:00
Nathaniel Nicandro
111d105b51 Add jupyter-repl-history-add tests 2019-05-18 20:35:28 -05:00
Nathaniel Nicandro
107fa8042d Generalize jupyter-repl-history navigation functions 2019-05-18 20:35:28 -05:00
Nathaniel Nicandro
497ba05aa5 Skip jupyter-write-connect-file test on Windows 2019-05-13 12:23:02 -05:00
Nathaniel Nicandro
18f108f144 Use jupyter-ert-info in jupyter-repl-prompts test 2019-05-13 12:23:02 -05:00
Nathaniel Nicandro
d01dd82713 Once again increase timeouts during tests 2019-05-13 12:23:02 -05:00
Nathaniel Nicandro
b6d221c835 Be more diligent with processes used during testing 2019-05-13 12:21:59 -05:00
Nathaniel Nicandro
0f06ea1407 Add jupyter-kernel-lifetime test 2019-05-10 17:28:04 -05:00
Nathaniel Nicandro
f7b0ab2bc1 Rework jupyter-requests-pending-p test
Getting failures on Appveyor
2019-05-09 20:10:49 -05:00
Nathaniel Nicandro
258d1edfdb Shutdown kernel after jupyter-command-kernel test 2019-05-09 19:49:45 -05:00
Nathaniel Nicandro
3f0a4b7829 Make jupyter-write-connection-file test more reliable 2019-05-09 19:49:45 -05:00
Nathaniel Nicandro
64d9c773df Make jupyter-weak-ref test more reliable 2019-05-09 12:51:00 -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
edb452618e jupyter-test-with-client-cache: Call accept-process-output 2019-05-09 10:36:43 -05:00
Nathaniel Nicandro
cdfefd5002 Increase timeouts during testing 2019-05-09 09:41:19 -05:00
Nathaniel Nicandro
5cd1e55616 org-babel-jupyter-strip-ansi-escapes: Handle blocks without results
Fixes #112.
2019-05-08 10:36:38 -05:00
Nathaniel Nicandro
4302da35ef Shutdown kernel properly when testing 2019-05-07 22:47:22 -05:00
Nathaniel Nicandro
e948d4f705 Try to make jupyter-weak-ref test more reliable 2019-05-07 22:47:22 -05:00
Nathaniel Nicandro
1d8f28f2fc Simplify test macros
Also fix misuse of `alist-get`. `alist-get` uses `assq` for comparison by
default, but we are comparing strings. This caused issues when caching REPL
buffers and the subsequent re-use of them during testing.
2019-05-07 17:30:16 -05:00
Nathaniel Nicandro
87d078edca Add more tests
* Add tests for `jupyter-weak-ref`, `jupyter-add-finalizer`, and `jupyter-eval`
2019-05-07 17:30:16 -05:00
Nathaniel Nicandro
112769e0c6
Bump version 2019-05-04 03:31:50 -05:00
Nathaniel Nicandro
c8dd1236df Generalize tests for Windows 2019-05-04 02:33:11 -05:00
Nathaniel Nicandro
4a07dc143e
Add test for jupyter-ioloop-wait-until 2019-05-04 01:27:54 -05:00
Nathaniel Nicandro
9dc814e38a
Add test for jupyter-connect-repl 2019-04-15 21:39:55 -05:00
Nathaniel Nicandro
cdc9d1fc6f Increase timeout when cleaning up test REPLs 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
82ec2fb786 Handle all valid arguments in client propagating advise
Fixes #76.
2019-04-01 21:45:00 -05:00
Nathaniel Nicandro
460eba73ec
Update tests to consider changes in message handling 2019-03-29 12:57:54 -05:00
Nathaniel Nicandro
2c005cab7b
jupyter-org-insert-src-block: Find the closest language to use
If `point' is not on a source block, look near `point' for a source block with
a Jupyter language and use that one.

Closes #66.
2019-03-29 00:37:38 -05:00
Nathaniel Nicandro
580776bf58 Add org-babel-jupyter-src-block-session 2019-03-28 23:29:02 -05:00
Nathaniel Nicandro
7ea17ae492
Refactor heartbeat channel
Mainly variable re-naming and in preparation for adding in auto-restart
support.

* `jupyter-hb-consider-dead-periods` -> `jupyter-hb-max-failures`

  * Also convert to a customizable variable

* `kernel-died-cb` -> `dead-cb`
2019-03-22 20:10:22 -05:00
Nathaniel Nicandro
3f3db53527 Handle ANSI escape sequences in org-mode src-block results 2019-03-20 21:08:53 -05:00