Commit graph

50 commits

Author SHA1 Message Date
Nathaniel Nicandro
becddfc9ea Fix requires
`jupyter-channels.el` depends on the `jupyter-send` method defined in
`jupyter-messages.el` whereas `jupyter-messages.el` does not depend on any
functions in `jupyter-channels.el`.

* jupyter-channel.el: Require `jupyter-messages`

* jupyter-messages.el: Remove `jupyter-channels` require
2018-11-08 21:30:32 -06:00
Nathaniel Nicandro
c30357badb jupyter-with-message-content: Allow debugging inside the macro 2018-10-31 18:49:37 -05:00
Nathaniel Nicandro
1697f44761 jupyter-with-message-content: Reword documentation 2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
e06e61e9fd jupyter-messages.el: Small documentation changes 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
e43c6597ad Add convenience macros for working with messages 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
c070f2d04d Update documentation and comments 2018-10-25 22:57:23 -05:00
Nathaniel Nicandro
0bf30538e6 Refactor encoding/decoding of message-part lists for readability 2018-10-16 13:55:57 -05:00
Nathaniel Nicandro
7b3e4f9f84 Fix encoding/decoding time objects
* Handle the case of no time specification by defaulting to midnight when
  decoding time

* Properly handle fractions in `jupyter--decode-time`

* Implement `jupyter--encode-time`

* Consider a time object to be a length 4 list of integers and encode the
  object using `jupyter--encode-time` when encoding in `jupyter--encode`

* Add tests for time decoding/encoding
2018-10-16 13:55:30 -05:00
Nathaniel Nicandro
ce3d9a377c Refactor jupyter--sign-message 2018-05-30 12:54:55 -05:00
Nathaniel Nicandro
122748b25e Do not pass the signature when signing message parts 2018-05-30 12:54:55 -05:00
Nathaniel Nicandro
7c218b233c Ensure that parts of a message that need to be dictionaries are encoded as such 2018-05-30 12:54:55 -05:00
Nathaniel Nicandro
70be58129e Rename jupyter-message-parent-message-type -> jupyter-message-parent-type 2018-05-30 12:49:28 -05:00
Nathaniel Nicandro
f4c931d57d Avoid double encoding, document message functions, small fixes to message functions
This introduces a way of keeping track of both the encoded and decoded parts of
a message, only decoding the parts of a message when needed, and only encoding
the parts of a message when needed.

If the objects passed to `jupyter--encode` or `jupyter--decode` are lists with
the first element being the symbol `message-part`, then the second element of
the list is interpreted as being the encoded message and the third element
being the decoded part of the message. If either the encoded or the decoded
part are nil, then `jupyter--encode` or `jupyter--decode` will fill those
message parts in and on subsequent calls, passing in the same list, no work
will need to be performed.

This avoids double encoding messages when relaying messages between the channel
subprocess and the browser displaying widgets. This speeds up the communication
process. The cost is storing two representations of the same message, i.e.
speed vs memory.

Fixes:

- Use `eq` instead of `equal` in message status predicates
- Fix time string decoding
  - `parse-time-string` was returning all nil on Emacs 26
- Include validation for parent header in `jupyter--encode-message`
- Use `jupyter-message-header' to access the message header instead of `plist-get`
2018-05-28 01:25:33 -05:00
Nathaniel Nicandro
436089d08b Prefer defun over defsubst and other miscellaneous changes
- Add missing namespace to sha256 function

  - Any function defined should have a `jupyter-` prefix

- Remove `cl-lib` dependency in `jupyter-messages.el`

- Include `subr-x` in `jupyter-base.el`

- Use `tramp-file-name-user` instead of `tramp-file-name-real-user` since the
  latter is missing in Emacs 26
2018-05-28 01:25:33 -05:00
Nathaniel Nicandro
9429438370 Use a websocket for communicating with the browser displaying widgets 2018-05-28 01:25:33 -05:00
Nathaniel Nicandro
bcf750c9a8 Handle binary buffers properly when decoding messages 2018-05-28 01:25:33 -05:00
Nathaniel Nicandro
17596ee1c4 Be less ambiguous when encoding/decoding messages
- Do not handle nil as an empty dictionary when encoding.

- Use the default `json-array-type`
2018-05-28 01:25:09 -05:00
Nathaniel Nicandro
554e519bf0 Avoid delays during message processing
- Allow specifying a msg-id before a call to `jupyter-send`

  - This avoid sending a message to the browser displaying the widgets on every
    message send to the kernel. The previous implementation generated a new ID
    without allowing the caller to pass one in.

- Simplify message polling by sending received messages from the kernel to the
  parent Emacs process at the moment of arrival.
2018-05-28 01:25:09 -05:00
Nathaniel Nicandro
50088df2e0 Add widget support 2018-05-28 01:25:09 -05:00
Nathaniel Nicandro
82c45fc3b9 Add jupyter-message-type-as-keyword 2018-05-28 01:25:09 -05:00
Nathaniel Nicandro
e3c7cce7c2 Add jupyter-message-parent-message-type 2018-05-28 01:25:09 -05:00
Nathaniel Nicandro
4edc22832b Override json-encode in jupyter--encode to take into account message types 2018-05-20 11:03:58 -05:00
Nathaniel Nicandro
1841e49b5d Be consistent with message types
Only use the message symbol's as defined in `jupyter-message-types` and switch
to the string representation only when sending a message.
2018-05-16 20:46:10 -05:00
Nathaniel Nicandro
7d7b7650b9 Mainly code style changes 2018-05-15 16:45:24 -05:00
Nathaniel Nicandro
53ebf1ad35 Ensure a unibyte representation when signing messages 2018-05-06 03:16:47 -05:00
Nathaniel Nicandro
9ddec6c469 Decode date fields into time objects in jupyter--decode 2018-05-05 23:16:01 -05:00
Nathaniel Nicandro
24eb475443 Cleanup comments 2018-02-12 10:25:13 -06:00
Nathaniel Nicandro
255247788c Remove uses of seq functions
Since this is an emacs 25 dependency and there were not many uses of these
functions, remove them.
2018-02-09 09:11:57 -06:00
Nathaniel Nicandro
3170a2305f Add documentation for jupyter-message convenience functions 2018-01-18 23:02:24 -06:00
Nathaniel Nicandro
5d9244b17b Rename jupyter--encode-object -> jupyter--encode, jupyter-decode-string -> jupyter--decode` 2018-01-09 00:44:35 -06:00
Nathaniel Nicandro
a7539dc37b Fix checkdoc warnings 2018-01-09 00:44:34 -06:00
Nathaniel Nicandro
326ff15d92 Add standard header comments 2018-01-09 00:44:33 -06:00
Nathaniel Nicandro
b3b1066624 Re-organization of code base
- `jupyter-client.el` only contains client related code

- `jupyter-kernel-manager` related code is placed in `jupyter-kernel-manager.el`

- Socket creating functions and generating connection info plist function are
  placed in `jupyter-connection.el`. This also contains the
  `jupyter-connection` class.

- Kernelspec related functions are placed in `jupyter-kernelspec.el`

- Move general utility functions and variables requires necessary for `jupyter`
  into `jupyter-base.el`. This also contains the `jupyter-session` and
  `jupyter-request` struct definitions.
2018-01-06 19:55:45 -06:00
Nathaniel Nicandro
b4a5ea177f Use defsubst for the functions that work with message plists
Also add more convenience functions for working with messages.
2018-01-02 13:50:24 -06:00
Nathaniel Nicandro
a224253a46 Rename jupyter--send-encoded -> jupyter-send, jupyter--recv-decoded -> jupyter-recv 2018-01-02 13:50:12 -06:00
Nathaniel Nicandro
940594fda6 Rename jupyter-request-* to jupyter-*-request
Where `jupyter-request-*` are the `jupyter-kernel-client` request methods. This
required the underlying messages request message functions to be renamed to
`jupyter-message-*-request` from `jupyter-*-request`.
2018-01-02 13:50:08 -06:00
Nathaniel Nicandro
714b23c12f Guard against empty messages when flags are used 2017-12-27 00:17:03 -06:00
Nathaniel Nicandro
6721f91b08 Only attempt to decode time when a date field exists 2017-12-27 00:16:11 -06:00
Nathaniel Nicandro
785c8242d8 Fix time decoding 2017-12-27 00:13:43 -06:00
Nathaniel Nicandro
2616f5d49b Decode datetime into time objects, add more convenience functions 2017-12-22 00:38:03 -06:00
Nathaniel Nicandro
72ab6b1d9e JSON encoded plists convert nil to {} 2017-12-21 18:10:19 -06:00
Nathaniel Nicandro
0f44d88874 Add fractional seconds in timestamp 2017-12-21 18:09:45 -06:00
Nathaniel Nicandro
1e246ee480 [WIP] Move all socket communication to a subprocess
With this new implementation, all communication between the kernel and the
client happens in a subprocess. When the client would like to send a message,
the parent emacs process generates the required plist and sends it to the
subprocess for encoding and sending to the kernel. When a message is received,
the subprocess decodes it and prints it to the pipe for the parent emacs
process to read.

This implementation also introduces the use of futures to avoid having to wait
for subprocess output when sending a message to the kernel. Every
`jupyter-request-*` function now returns a primitive future object which is
just a cons cell with the `car` equal to `:jupyter-future`. When the `cdr` of
the future is non-nil, then it is the message ID of the sent request. This acts
as a check to ensure that the message ID is available from the future object,
if the `cdr` is nil the ID is not available, but if the `cdr` is non-nil then
it is the message ID. The convenience function `jupyter-ensure-id` ensures that
the message ID is available and returns the ID.

The future acts as a stand in for the message ID of the encoded request which
will be retrieved from the subprocess once the message has been encoded and
sent to the kernel. This future object is meant to be passed to
`jupyter-add-receive-callback` and other related functions the same way as an
actual message id.
2017-12-17 02:53:15 -06:00
Nathaniel Nicandro
ac8322cb97 More documentation on variables 2017-12-15 22:29:05 -06:00
Nathaniel Nicandro
ede2dacdd4 Convenience functions for handling messages 2017-12-15 22:28:45 -06:00
Nathaniel Nicandro
ad53e098f6 Move jupyter--received-message-types to jupyter-messages.el
Also fix naming issue, previously `recieved` when it should have been `received`.
2017-12-15 18:16:53 -06:00
Nathaniel Nicandro
d2654de9f6 Use the random state that is already present for generating UUID's
`cl-make-random-state` only creates a random state based on time with seconds
resolution.
2017-12-14 16:14:12 -06:00
Nathaniel Nicandro
725648e10d All messages sent use keys
Also use a variable `jupyter--false` instead of `:json-false` for possibly
supporting other encodings in the future.
2017-12-14 13:53:52 -06:00
Nathaniel Nicandro
bab7305cc8 Mark functions as private 2017-12-14 13:53:48 -06:00
Nathaniel Nicandro
76cf1c5eb7 Semi working prototype 2017-12-13 11:27:13 -06:00