Commit graph

1797 commits

Author SHA1 Message Date
Nathaniel Nicandro
2ff99918d2 Remove unnecessary function call
* jupyter-kernel-manager.el (initialize-instance): Remove
  `jupyter-kernel-alive-p` call.  This check is already done by
  `jupyter-kill-kernel`.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
ebf67c475e Remove two methods of jupyter-kernel-process-manager
There was an implementation of `jupyter-start-channels` for a
`jupyter-kernel-process-manager` due to the manager being able to send messages
to the kernel via a kernel's control channel.  The channel currently serves as
an implementation detail of the manager class, don't allow its status to be
controlled outside of the manager class by removing the implementation.

In addition, remove the `jupyter-stop-channels` implementation since
it is no longer needed.

* jupyter-kernel-manager.el (jupyter-start-kernel): Remove call to
`jupyter-start-channels` on MANAGER.  This should not have been done in the
first place since only `jupyter-kernel-process-manager` implemented that
method, as explained.  Also remove the `jupyter-kernel-alive-p` call, this is
already done in an :around method of `jupyter-kernel-alive-p`, see
`jupyter-kernel-lifetime`.

* jupyter-kernel-process-manager.el
(jupyter-start-channels, jupyter-stop-channels)
[jupyter-kernel-process-manager]: Remove. For `jupyter-stop-channels`, expand
body at call site.
(jupyter-start-kernel) [jupyter-kernel-process-manager]:  Start the control
channel as a final step.
(jupyter-shutdown-kernel, jupyter-interrupt-kernel): Remove
`jupyter-start-channels` call.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
1fa6ed4e5f Remove the jupyter-ioloop-handler method
Replace it with a handler function passed to `jupyter-ioloop-start`.

* jupyter-ioloop-comm.el: Do it.

* jupyter-channel-ioloop-comm.el: Do it.

* jupyter-channel-ioloop-comm.el: Do it.

* jupyter-ioloop.el: Do it. Update comments and doc.
(jupyter-ioloop--delete-process): Remove. It was used to perform
cleanup when the object used for dispatching to a handler method was
garbage collected. Since we no longer rely on having an object for
dispatching, preferring just a function to call, its not needed.

(jupyter-ioloop--make-filter): Fall back to calling handler function
instead of `jupyter-ioloop-handler`. Only handle ioloop start/stop
events internally. This means we can remove the check for those in
`jupyter-ioloop-comm`.

* test/jupyter-test.el: Update tests to take into account above
  changes.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
786f61fb99 Remove jupyter-session based jupyter-ioloop-start implementation
This in preparation for removing the `jupyter-ioloop-handler` method
altogether.

* jupyter-ioloop-comm.el
(jupyter-channel-ioloop--set-session): Promote to public function.
(jupyter-ioloop-start): Remove `jupyter-session` based
implementation. Preferring sub-classes to call
`jupyter-channel-ioloop-set-session`.

* jupyter-channel-ioloop-comm.el
(jupyter-comm-initialize): Use the newly public function.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
5d2007d5f2 Fix ordering of system-type check
We would still like a message indicating that a kernel process starts on
Windows.

* jupyter-kernel-process-manager.el
(jupyter-start-kernel) [jupyter-spec-kernel]: Do it.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
6be4f79ab3 Add jupyter-read-connection
* jupyter-base.el (jupyter-read-connection): New function.

* jupyter-kernel-process-manager.el
(jupyter-start-kernel) [jupyter-command-kernel]: Use it.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
c36f6fd63a Query for a kernel with point at the last place a user left it
`jupyter-org-closest-jupyter-language` falls back to asking a user for a
kernel, when it does so `point` is at the beginning of the buffer. Make sure
`point` is at the location where the user last left it.

* jupyter-org-extensions.el (jupyter-org-closest-jupyter-language): Do it.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
026c3fac61 Use :extra methods for org-babel-jupyter-parse-session
* ob-jupyter.el
(org-babel-jupyter-server-session)
(org-babel-jupyter-parse-session): Convert to method and re-implement
with :extra methods.

* test/jupyter-server-test.el
(org-babel-jupyter-server-session): New test.

* test/jupyter-test.el
(org-babel-jupyter-parse-session): Move test of server based sessions
to the new test.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
7735d2b8fb Fix typo 2021-04-06 21:12:45 -05:00
Nathaniel Nicandro
303a8f2e81 Don't narrow to REPL cell when fontifying syntactically
There is no need to do so since
`jupyter-repl-font-lock-fontify-region` already takes care of
narrowing to cell bounds and `font-lock-syntactic-face-function` is
called during the fontification process of the narrowed cell.
2021-04-04 12:45:11 -05:00
Nathaniel Nicandro
477dcfd71c Don't add the font-lock-multiline property to finalized cell text
The boundaries of cell text are already considered by
`jupyter-repl-map-cells` (called during fontification) so there is no
need to, in addition, have the `font-lock-multiline` property (see the
documentation of `font-lock-extend-region-functions` for what that
property is meant to do).

With regards to the comment, since the buffer is narrowed to the cell
text during fontification, syntactic fontification is contained within
the cell.
2021-04-04 12:45:11 -05:00
Nathaniel Nicandro
d1c6f74ead Remove jupyter-(send|recv) methods of a jupyter-session object
There is no need to have an extra function call and they were not used
anywhere else.

* jupyter-zmq-channel.el
(jupyter-send, jupyter-recv) [jupyter-session]: Remove. Update all
callers.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
04330c4dd3 Move declaration
* jupyter-base.el: Do it.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
1c154ca68d Re-work jupyter-request documentation
* jupyter-base.el: Do it.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
c3fae7d7df jupyter-request-idle-received-p -> jupyter-request-idle-p
but first...

* jupyter-base.el: ...idle-received-p -> idle-p for jupyter-request objects

* jupyter-client.el: ...then, do it.

* test/jupyter-test.el: Do it.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
7ca3344c1b Add syncing functions
These will be used in future commits.

* jupyter-client.el (jupyter-idle-sync)
(jupyter-add-idle-sync-hook): New functions.

* test/jupyter-test.el (jupyter-idle-sync): New test.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
d6aced9e71 Rename internal functions for clarity
The following changes are made:

jupyter--run-handler-p -> jupyter--request-allows-handler-p
jupyter--handler-dispatch -> jupyter--run-handler

* jupyter-client.el: Do it.

* test/jupyter-test.el: Do it.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
7786d30468 Refactor message sending/receiving
`jupyter-handle-*` methods now only take an argument list like

    (client req msg)

instead of each method being passed an expanded list of arguments
unpacked from a message contents. Not sure why the unpacking was done
in the first place. The strategy now is to use
`jupyter-with-message-contents` when accessing the contents of a
message.

* jupyter-client.el
(define-jupyter-client-handler)
(define--jupyter-client-sender): New macros.
(jupyter-send-execute-request)
(jupyter-send-inspect-request)
(jupyter-send-complete-request)
(jupyter-send-history-request)
(jupyter-send-is-complete-request)
(jupyter-send-comm-info-request)
(jupyter-send-comm-open)
(jupyter-send-comm-msg)
(jupyter-send-comm-close)
(jupyter-send-kernel-info-request)
(jupyter-send-shutdown-request): Use `define--jupyter-client-sender`.
(jupyter-handle-input-request)
(jupyter-handle-execute-reply)
(jupyter-handle-inspect-reply)
(jupyter-handle-complete-reply)
(jupyter-handle-history-reply)
(jupyter-handle-is-complete-reply)
(jupyter-handle-comm-info-reply)
(jupyter-handle-kernel-info-reply)
(jupyter-handle-shutdown-reply)
(jupyter-handle-comm-open)
(jupyter-handle-comm-close)
(jupyter-handle-stream)
(jupyter-handle-execute-input)
(jupyter-handle-execute-result)
(jupyter-handle-error)
(jupyter-handle-status)
(jupyter-handle-clear-output)
(jupyter-handle-display-data)
(jupyter-handle-update-display-data): Use
`define-jupyter-client-handler`.

* jupyter-org-client.el
(jupyter-handle-stream)
(jupyter-handle-error)
(jupyter-handle-execute-result)
(jupyter-handle-display-data)
(jupyter-handle-execute-reply): Update to take into account changes in
the argument lists of `jupyter-handle-*` methods.

* jupyter-python.el
(jupyter-handle-error): Ditto.

* jupyter-repl.el
(jupyter-handle-execute-reply)
(jupyter-handle-execute-result)
(jupyter-handle-clear-output)
(jupyter-handle-display-data)
(jupyter-handle-update-display-data)
(jupyter-handle-status)
(jupyter-handle-stream)
(jupyter-handle-error):
(jupyter-handle-history-reply)
(jupyter-handle-shutdown-reply): Ditto.

* jupyter-widget-client.el
(jupyter-handle-comm-open)
(jupyter-handle-comm-close)
(jupyter-handle-comm-msg): Ditto.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
9205805935 Refactor jupyter-handle-message and related
Reduce the number of arguments `jupyter-handle-message` takes, by just
passing the message property list directly. Expanding out the
arguments just creates unnecessary work.  Make the
`jupyter-kernel-client' implementation of `jupyter-handle-message`
more readable. Remove the unnecessary and confusing handler method
dispatching. Document `jupyter-handle-message`.

* README.org: Update reference to `jupyter-handle-*` method.

* jupyter-client.el
(jupyter-dispatch-messages-cases): Remove.
(jupyter-run-hook-with-args-until-success): Remove.
(jupyter-handle-message-p): New function. Similar to the above except
its return value is negated.
(jupyter--client-handlers): New variable. Holds the table of message
handlers.
(jupyter--handler-dispatch): Use them.
(jupyter--run-callbacks): Change to `defsubst`
(jupyter--run-handler-maybe): Remove. Expand out at call sites, replace
`jupyter-handle-message` with `jupyter--handler-dispatch` at the sites.
(jupyter--handler-dispatch): New function. Unifies all the
`jupyter-handle-message` implementations for channels.
(jupyter--update-execution-state, jupyter--message-completes-request-p): New functions.
(jupyter-handle-message): Remove channel implementations.  Use the new
functions in the client implementation.
2021-04-03 12:22:44 -05:00
Yuri D. Lensky
9285480715 Update jupyter--encode for new Emacs JSON API.
The old Emacs JSON API (for versions <= 27.2 at time of commit) was
structured in a way that replacing the symbol-function of json-encode
worked to get custom encoding for certain object types used by
emacs-jupyter. In the later API, the function json--print plays the
recursive role of json-encode. The code here works in either version,
and is simplified so that future updates to the API are easier to
accomodate.
2021-04-02 21:04:13 -05:00
Nathaniel Nicandro
3f54271e40 Update Travis build 2021-04-02 15:12:20 -05:00
Nathaniel Nicandro
1a5ec3171f README Changes 2021-04-02 12:14:22 -05:00
Tim Quelch
6ce8d01e3a Fix minor typo (resourse -> resource) 2021-01-15 20:57:19 -06:00
Daniel Kraus
7372a11706 Require eieio for jupyter-channel defclass 2021-01-15 20:55:57 -06:00
Nathaniel Nicandro
360cae2c70 Update README 2020-08-02 12:46:52 -05:00
Nathaniel Nicandro
64dda221c0 Remove .github/FUNDING.yml 2020-07-31 17:34:34 -05:00
Nathaniel Nicandro
785edbbff6 Fix missing function
`jupyter-server-make-instance` is from another branch.

* ob-jupyter.el: Remove `jupyter-server-make-instance` declaration.
(org-babel-jupyter-initiate-client): Replace its use with `jupyter-server`.
2020-04-17 14:07:06 -05:00
Nathaniel Nicandro
62ad054001 Fix undefined variable
* jupyter-R.el (jupyter-org-result): Do it.
2020-04-15 19:37:28 -05:00
Nathaniel Nicandro
a9ae0bcef5 Replace jupyter-repl-cell-cond with jupyter-repl-map-cells
* jupyter-repl.el
(jupyter-repl-map-cells): New function.
(jupyter-repl-cell-cond): Remove. Update callers with new function.

* jupyter-julia.el: Ditto.

* test/jupyter-test.el
(jupyter-repl-map-cells): New test.
(jupyter-repl-cell-cond): Remove.
2020-04-14 17:18:38 -05:00
Nathaniel Nicandro
25270f7d3b Remove some method implementations
The `jupyter-kill-kernel` of a kernel manager serves no purpose, just
use `jupyter-shutdown-kernel`.

* jupyter-kernel-manager.el
(jupyter-kill-kernel) [jupyter-kernel-manager]: Remove.

* jupyter-server.el (jupyter-kill-kernel) [jupyter-server-kernel-manager]: Remove.
2020-04-14 17:05:28 -05:00
Nathaniel Nicandro
a7dbff9aa3 Refactor source block overriding mechanism
This commit adds the function `org-babel-jupyter--babel-map` and some
auxiliary functions to simplify the code for source block
overriding. The old implementation was very hard to follow, these
changes should hopefully make the code more readable.

* ob-jupyter.el (org-babel-jupyter--override-restore-header-args)
(org-babel-jupyter--override-restore-src-block): Remove.
(org-babel-jupyter--babel-vars): New variable.
(org-babel-jupyter--babel-op-symbol)
(org-babel-jupyter--babel-var-symbol)
(org-babel-jupyter--babel-map): New functions.
(org-babel-jupyter-override-src-block)
(org-babel-jupyter-restore-src-block)
(org-babel-jupyter-make-language-alias): Use them.
2020-04-14 17:05:28 -05:00
Nathaniel Nicandro
71789f7cfd Remove more jupyter-channels-running-p implementations
The implementations are really aliases of `jupyter-comm-alive-p` so
keep that one instead.  The `jupyter-channels-running-p` method is a
remnant of an older design, still used by `jupyter-kernel-client'
though.

* jupyter-channel-ioloop-comm.el: Do it.

* jupyter-server.el: Do it.
2020-04-14 17:05:28 -05:00
Nathaniel Nicandro
6baecc9a90 Reduce number of arguments of jupyter-org-result
This groups the DATA and METADATA argument of `jupyter-org-result`
into a CONTENT argument to finish up a change made in a previous
commit that removed `jupyter-loop-over-mime`.  The METADATA argument
is rarely if every used, so it doesn't make sense to have all those
method implementations have to provide it.

* jupyter-org-client.el
(jupyter-org--image-result): Change group DATA and METADATA into a
CONTENT argument.  Change argument ordering.  Update all callers.
Cleanup the documentation to reflect the changes.
(jupyter-org-result): Similarly, group those two arguments into the
one argument.  Update all callers in this file, also...

* README.org: ...here

* jupyter-R.el: ...here

* jupyter-python.el: ...and here
2020-04-14 17:05:28 -05:00
Nathaniel Nicandro
e400266ce1 Replace the jupyter-loop-over-mime macro
It is replaced with `jupyter-map-mime-bundle` which is a function.

* jupyter-base.el (jupyter-loop-over-mime): Remove.
(jupyter-map-mime-bundle): New function. Update call sites of the
removed function, with calls to this function.
(jupyter-normalize-data): Return a mime bundle, a property list with
:data and :metadata keys.  Update all callers.

* jupyter-mime.el (jupyter-insert): Updated to take into account the
  previously mentioned changes.

* jupyter-org-client.el (jupyter-org-result): Ditto.

* test/jupyter-test.el (jupyter-loop-over-mime): Rename to
  `jupyter-map-mime-bundle` and update the test to consider it.
2020-04-14 15:46:38 -05:00
Nathaniel Nicandro
90e0c06f2e Use and in one place
* jupyter-org-client.el (jupyter-org--append-stream-result-p): Do it.
2020-04-14 12:25:28 -05:00
Nathaniel Nicandro
7d61c82567 Do not delete a character that isn't expected
* jupyter-org-client.el (jupyter-org--append-to-example-block): Do it.
2020-04-14 12:25:08 -05:00
Nathaniel Nicandro
adcc853183 Use pcase in one place
* jupyter-org-client.el (jupyter-org--find-mime-types): Do it.
2020-04-14 12:24:42 -05:00
Nathaniel Nicandro
4a0617132f Use cl-callf2 in a few places
* jupyter-comm-layer
(jupyter-comm-add-handler, jupyter-comm-remove-handler): Do it.
2020-04-14 12:24:11 -05:00
Nathaniel Nicandro
91ca722b63 Remove unused code
The `jupyter-zmq-channel-comm.el` file was more of an experiment and
is unused.  It also causes failures on Emacs 27 due to missing
`thread-alive-p` function in 27.

* jupyter-zmq-channel-comm.el: Remove.

* test/jupyter-test.el: Remove the related `require`.  Re-work tests
  that used `jupyter-zmq-channel-comm` to not use it.
2020-04-14 12:23:51 -05:00
Nathaniel Nicandro
97c421a698 Fix regression
In `org-babel-jupyter-initiate-session-by-key`, the function to
disassociate a client from a :session was added to the
`current-buffer`s value of `kill-buffer-hook` but it should be added
to the REPL buffer's value of that hook.

fixes #240

* ob-jupyter.el
(org-babel-jupyter-initiate-session-by-key): Add to the local value of
`kill-buffer-hook` in the REPL's buffer.

* test/jupyter-test.el
(org-babel-jupyter-initiate-session-by-key): New test.
2020-04-14 11:36:40 -05:00
Nathaniel Nicandro
587ed4e029 Keep uppercase characters in kernel language names
Converting to lowercase was done arbitrarily.  So that one could write
`(jupyter-lang wolfram-language)` instead of
`(jupyter-lang Wolfram-Language)`.

fixes #241

* CHANGELOG.org: Add note.

* README.org: Update relevant sections.

* jupyter-base.el (jupyter-canonicalize-language-string): Do it.

* ob-jupyter.el (org-babel-jupyter-aliases-from-kernelspecs):
2020-04-09 11:33:57 -05:00
Nathaniel Nicandro
82f8fe691e Set back to dev 2020-04-07 15:43:10 -05:00
Nathaniel Nicandro
403c70c83c Bump version 2020-04-07 15:13:51 -05:00
Nathaniel Nicandro
4c9e616690 ob-jupyter.el: Add more documentation
* ob-jupyter.el: Do it.
2020-04-07 12:24:34 -05:00
Nathaniel Nicandro
a997e34001 Move kludge outside of org-babel-jupyter-make-language-alias
That function should just create the function aliases and define the necessary
variables if not already defined.  It should not also set the :kernel header
argument if it isn't present in the org-babel-default-header-args:jupyter-LANG
variable.

* ob-jupyter.el (org-babel-jupyter-make-language-alias): Remove setting of :kernel.
(org-babel-jupyter-aliases-from-kernelspecs): Set :kernel after creating a
language alias.
2020-04-07 12:11:59 -05:00
Nathaniel Nicandro
16ea58e59e Use pcase-let to reduce verbosity
* ob-jupyter.el
(org-babel-jupyter-initiate-client) [org-babel-jupyter-remote-session]: Do it.
2020-04-07 09:00:35 -05:00
Nathaniel Nicandro
8c840d42d3 Fix typo
* ob-jupyter.el (org-babel-jupyter-initiate-client): Do it.
2020-04-06 12:36:36 -05:00
Nathaniel Nicandro
dc8fc6767f Silence byte compiler 2020-04-04 21:17:37 -05:00
Nathaniel Nicandro
0c2531402e Fix wrong number of arguments
* ob-jupyter.el (org-babel-prep-session:jupyter)
(org-babel-load-session:jupyter): Fix number of arguments to
`org-babel-jupyter--insert-variable-assignments`.
2020-04-04 21:17:37 -05:00
Nathaniel Nicandro
d336cdcace Unify code waiting for kernel processes to be ready
* jupyter-kernel-process-manager.el
(jupyter--after-kernel-process-ready): New macro.
(jupyter-start-kernel [jupyter-command-kernel, jupyter-spec-kernel]): Use it.
(jupyter--block-until-conn-file-access): Remove.
2020-04-04 21:17:37 -05:00