Commit graph

286 commits

Author SHA1 Message Date
Nathaniel Nicandro
a7148927fe Add jupyter-repl-propertize-regex
Previously, when propertizing the output of the REPL, a regular expression was
generated every time to take into account the comment characters of the kernel
language. Adding this variable ensure that we only create the expression once.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
4ad72e4781 Rename jupyter-output-buffer-* to jupyter-display-buffer-*
An output buffer implies output from the kernel, but they are used for more
general purposes other than displaying output form the kernel.
2018-11-26 12:37:37 -06:00
Nathaniel Nicandro
99c0bf0f55 Remove unused code 2018-11-21 12:35:34 -06:00
Nathaniel Nicandro
fca89359fd Rename jupyter-repl-display-traceback to jupyter-display-traceback
Also move the function to jupyter-client.el from jupyter-repl.el

* jupyter-repl.el (jupyter-repl-display-traceback): Do it.

* jupyter-client.el (jupyter-display-traceback): Do it.
2018-11-21 12:35:34 -06:00
Nathaniel Nicandro
6a1da44904 Move evaluation functions from jupyter-repl.el to jupyter-client.el
These functions are general and not only useful for REPLs.
2018-11-19 08:50:32 -06:00
Nathaniel Nicandro
c859d34faf Add jupyter-repl-cell-output
* jupyter-repl.el (jupyter-repl-cell-output): Do it.
2018-11-17 15:24:11 -06:00
Nathaniel Nicandro
6aed12011a jupyter-repl-append-output: Mark output as read only
This used to be done by `jupyter-repl-insert`, but this is no longer the case
as all insertion of results is handled by the functions in jupyter-mime.el
while `jupyter-repl-insert` is more specific to insertion in the REPL buffer.
2018-11-17 11:47:55 -06:00
Nathaniel Nicandro
78a0747ddb Call after change function only when change is due to cell code
* jupyter-repl.el (jupyter-repl-do-after-change): Do it.
(jupyter-repl-after-change): Remove check that is now done at a higher level.
2018-11-16 17:22:10 +00:00
Nathaniel Nicandro
081f329da1 v0.6.0 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
a9add47b6f jupyter-repl-kill-buffer-query-function: Stop the client's channels
Although the client's channels are cleaned up when it goes out of scope, there
may be some stray messages that come through before that occurs. If they
do, they will attempt to access a killed buffer. Prevent that.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
823ea8adde Fix checkdoc warnings 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
134f84a59c Add object finalizer class
* jupyter-base.el (jupyter-finalized-object): New class.
(initialize-instance): New method addition.
(jupyter-add-finalizer): New method.

* jupyter-client.el (jupyter-kernel-client):
Inherit from jupyter-finalize-object.
(initialize-instance): Cleanup private buffer when client loses scope.
(jupyter-finalize): Remove.

* jupyter-kernel-manager.el (jupyter-kernel-manager):
Inherit from jupyter-finalized-instance.
(jupyter-kernl-manager--cleanup): New function.
(jupyter-finalize, jupyter-kill-kernel-managers): Remove. Update all callers.
(jupyter--kernel-sentinel): Remove MANAGER argument. Update all callers.
(jupyter--start-kernel): Remove MANAGER argument. Update all callers.
(jupyter-start-kernel): Add finalizer to kernel process to cleanup conn-file.

* jupyter-repl.el (jupyter-repl-kill-buffer-query-function):
Remove calls to jupyter-finalize.
2018-11-15 23:02:41 -06:00
Nathaniel Nicandro
8f0acca6df Move output buffer related functions to jupyter-base.el
* jupyter-repl.el (jupyter-output-buffer-marker, jupyter-output-buffer-request-id):
(jupyter--reset-output-buffer-p, jupyter-with-output-buffer): Do it.
(jupyter-repl-get-special-buffer): Do it and rename to jupyter-get-buffer-create.

* jupyter-client.el: See above.
2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
ba13ef2419 Move inspection related functions to jupyter-client.el
* jupyter-repl.el (jupyter-inspect, jupyter-inspect-at-point): Do it.

* jupyter-client.el: See above.
2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
af32a3352f Promote the execution-state to be a slot of jupyter-kernel-client
* jupyter-client.el (jupyter-kernel-client): Do it.
(jupyter-run-hook-with-args-until-success): Pass client as first argument to
hooks.
(jupyter-execution-state): New convenience function.
(jupyter--set-execution-state): New helper function. Add as global IOPUB
message hook to set the execution-state slot.

* jupyter-repl.el (jupyter-repl-client): Remove execution-state slot.
(jupyter-handle-status): Don't set the execution-state slot.
(jupyter-repl-ret, jupyter-repl-interaction-mode-line): Use
jupyter-execution-state.
(jupyter-repl-initialize-hooks): Take into account changes to message hooks.

* jupyter-kernel-manager (jupyter-start-new-kernel): Update callback.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
bd5d4d3eea jupyter-repl-append-output: Revert usage of with-silent-modifications
Font locking is actually still needed when appending output. It's not enough to
temporarily disable it and insert since the text we inserted doesn't get font
locked properly. This is most notable when inserting markdown text.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
c4f37a0156 Implement rudimentary Jupyter display API
Adds methods which operate on Jupyter displays. A Jupyter display is a part of
the frame tagged with a display ID. The current implementation just associates
part of a buffer with a jupyter-display text property and demarcates the
beginning of a display with a jupyter-display-begin property.

* jupyter-mime.el (jupyter-current-display):
(jupyter-beginning-of-display):
(jupyter-end-of-display):
(jupyter-next-display-with-id):
(jupyter-delete-current-display): New methods to work with display IDs.
(jupyter-update-display): Ditto. Was previously a function.

* jupyter-repl.el (jupyter-handle-display-data): Remove handling of
`jupyter-display-ids`.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
8146fe660f Move display ID routines from jupyter-repl.el to jupyter-mime.el
jupyter-mime.el might not be the best place for these functions but they are
moved there because that is the current location of `jupyter-insert-with-id`.

* jupyter-repl.el (jupyter-repl-next-display-with-id):
(jupyter-repl-update-display): Move to jupyter-mime.el, replace `jupyter-repl-`
prefix with `jupyter-`.
(jupyter-delete-display-at-point): Move to jupyter-mime.el.
(jupyter-handle-update-display-data): Replace occurrence of
`jupyter-repl-update-display` with `jupyter-update-display`.

* jupyter-mime.el (jupyter-next-display-with-id):
(jupyter-delete-display-at-point):
(jupyter-update-display): Moved from jupyter-repl.el, which see. Promote
`jupyter-next-display-with-id` and `jupyter-delete-display-at-point` to
methods. This is in anticipation of having other kinds of displays besides text
in a buffer, e.g. controlling the display of an external browser.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
321efd4c9c Refactor jupyter-repl-update-display
* jupyter-repl.el (jupyter-delete-display-at-point): New helper function.
(jupyter-repl-update-display): Use new helper function. Use
`jupyter-with-insertion-bounds` to obtain the region to highlight after
insertion. Use `jupyter-insert-with-id` for insertion. Use
`pulse-momentarily-highlight-region`.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
e01f8df624 Remove jupyter-repl-insert-message
The purpose of this function was to conveniently insert a message property list
and allow contributors to perform post insert fixing up depending on the
mimetype inserted via the method `jupyter-repl-after-insert-message`. This same
effect can be done by extending `jupyter-insert` without the need of adding a
new method.

* jupyter-repl.el (jupyter-repl-insert-message):
(jupyter-repl-after-insert-message): Remove.
(jupyter-inspect): Replace calls to `jupyter-repl-insert-message` with
`jupyter-insert`.

* jupyter-python.el (jupyter-repl-after-insert-message): Replace with
`jupyter-insert` :around method.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
75a08c26d0 Implement jupyter-insert method
The goal of this method is to act as a single entry point for insertion of
kernel results in any context. One would simply add another method to handle a
specific context.

* jupyter-base.el (jupyter-mime-types):
(jupyter-nongraphic-mime-types): New variables that give mime-types that can be
handled.
(jupyter-insert): New method for dispatching to code that inserts mimetype
representations in the current buffer.

* jupyter-mime.el: New file.
(jupyter-display-ids):
(jupyter-handle-control-codes):
(jupyter-fontify-buffers):
(jupyter-get-fontify-buffer):
(jupyter-fixup-font-lock-properties):
(jupyter-add-font-lock-properties):
(jupyter-fontify-according-to-mode):
(jupyter-insert-html):
(jupyter-markdown-mouse-map):
(juputer-markdown-follow-link-at-point):
(jupyter-insert-markdown):
(jupyter-insert-latex):
(jupyter-insert-ansi-coded-text): Moved from jupyter-repl.el, replaced
`jupyter-repl-` prefix with `jupyter-`.
(jupyter--shr-put-image): Ditto. Also add `shr-` prefix.
(jupyter--delete-javascript-tags): Ditto. Also mark as private functions.
(jupyter-insert-image): Ditto. Also mark as a public function.
(jupyter-insert): (DISPLAY-ID ...) Moved from jupyter-repl.el. Was
`jupyter-repl-insert-data-with-id`.
(jupyter-with-control-code-handling):
(jupyter-markdown-follow-link): Moved from jupyter-repl.el
(jupyter-insert): Implement methods to do the work previously done by
`jupyter-repl-insert-data`.

* jupyter-repl.el (jupyter-repl-graphic-mimetypes): Moved to jupyter-base.el,
 inverted and renamed to `jupyter-nongraphic-mime-types`.
(jupyter-repl-graphic-data-p): Remove unused function.
(jupyter-repl-insert-data): Remove, replace calls with `jupyter-insert`.
(jupyter-repl-add-font-lock-properties):
(jupyter-repl-fixup-font-lock-properties):
(jupyter-repl-get-fontify-buffer):
(jupyter-repl-fontify-according-to-mode):
(jupyter-repl-delete-javascript-tags):
(jupyter-repl-put-image):
(jupyter-repl-insert-html):
(jupyter-repl-markdown-mouse-map):
(jupyter-repl-markdown-follow-link-at-point):
(jupyter-repl-insert-markdown):
(jupyter-repl-insert-latex):
(jupyter-repl--insert-image): Moved to jupyter-mime.el, which see.
(jupyter-repl-insert-data-with-id): Ditto. Changed to a `jupyter-insert` method
dispatched on a string argument.
(jupyter-repl-insert-ansi-coded-text): Ditto. Replace calls with
`jupyter-insert-ansi-coded-text`.
(jupyter-with-control-code-handling):
(jupyter-markdown-follow-link): Moved to jupyter-mime.el.

* jupyter-org-client.el (jupyter-handle-error): Replace
  `jupyter-repl-insert-ansi-coded-text` with `jupyter-insert-ansi-coded-text`.

* jupyter-tests.el (jupyter-insert): Add tests for `jupyter-insert`
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
dcd6e0fd25 Add jupyter-with-insertion-bounds
This function will prove useful in the future for applying text properties to
inserted text once the new `jupyter-insert` method is introduced.

* jupyter-base.el (jupyter-with-insertion-bounds): Add the new macro.

* jupyter-repl.el (jupyter-with-control-code-handling): Use it.
2018-11-10 08:41:13 -06:00
Nathaniel Nicandro
3241b47609 jupyter-repl-insert-html: Fix insertion of XHTML (#4)
Fixes #4. `shr` uses `libxml-parse-html-region` internally which converts all
tags and attributes to lowercase when constructing the DOM since HTML is
case-insensitive. But SVG uses XML which is a case-sensitive language. This
means that a conversion from the DOM back to an XML representation does not
restore the case of tags/attributes if `libxml-parse-html-region` is used. This
is solved by using `libxml-parse-xml-region` which preserves case.

* jupyter-repl.el (jupyter-repl-put-image): New function.
(jupyter-repl-insert-html): Temporarily bind libxml-parse-html-region to
libxml-parse-xml-region. Temporarily bind shr-put-image-function to
jupyter-repl-put-image.
2018-11-09 08:13:01 -06:00
Nathaniel Nicandro
4d4da4fcdc jupyter-repl-insert-data: Support image/jpeg
jupyter-repl.el (jupyter-repl-graphic-mimetypes): Add :image/jpeg.
(jupyter-repl-insert-data): Add the support.
2018-11-08 23:07:29 -06:00
Nathaniel Nicandro
fb55644d17 jupyter-repl-propertize-output: Also add text properties to ` character
For the Julia kernel.
2018-11-08 21:33:30 -06:00
Nathaniel Nicandro
7aac141275 jupyter-repl-connected-p: Simplify heartbeat check 2018-11-08 21:21:23 -06:00
Nathaniel Nicandro
22796ad4cd jupyter-client.el: Add jupyter-clients
* jupyter-client.el: Add the function

* jupyter-repl.el (jupyter-repl-available-repl-buffers): Use it. Ensure REPL
buffers are still live.
2018-11-08 21:15:22 -06:00
Nathaniel Nicandro
6a7a6aa4b3 jupyter-with-output-buffer: Properly initialize jupyter-output-buffer-marker 2018-11-07 12:54:15 -06:00
Nathaniel Nicandro
172f29b4fe jupyter-repl-propertize-output: Fix infinite loop
* If `comment-start` is nil, using a regular expression with an empty or clause
  causes an infinite loop. Ensure that we only add the or clause when
  `comment-start` is non-nil in `jupyter-repl-propertize-output`.

* Copy over the `comment-start` from the REPL language buffer in
  `jupyter-repl-initialize-fontification`
2018-11-07 12:20:33 -06:00
Nathaniel Nicandro
05bbe0414d Rename jupyter-startup-timeout to jupyter-long-timeout 2018-11-05 00:00:08 -06:00
Nathaniel Nicandro
50f797168d Add jupyter-repl-previous-cell-count 2018-11-04 23:56:42 -06:00
Nathaniel Nicandro
0fc402cd6b Add jupyter-repl-cell-reset-prompt 2018-11-04 23:56:42 -06:00
Nathaniel Nicandro
d86eea253b jupyter-handle-status: Force a mode line update after changing status 2018-11-04 23:56:42 -06:00
Nathaniel Nicandro
bd2333a432 Only consider the REPL buffer modified when editing an input cell 2018-11-04 23:56:42 -06:00
Nathaniel Nicandro
983ccf6ec7 Add jupyter-with-control-code-handling
This macro takes care of any ANSI control codes that the kernel output may
produce.
2018-11-04 23:56:42 -06:00
Nathaniel Nicandro
6c6712bb0a jupyter-with-output-buffer: Refactor
* Rename `jupyter-repl-output-buffer-marker` to `jupyter-output-buffer-marker`

* Rename `jupyter-repl-output-buffer-last-request-id` to
  `jupyter-output-buffer-request-id`

* Add `jupyter--reset-output-buffer-p` which returns non-nil if the current
  input buffer should be reset.

* Simplify the `jupyter-with-output-buffer` macro
2018-11-04 23:56:42 -06:00
Nathaniel Nicandro
4cfa8b19fc jupyter-repl-eval-string: Simplify conditional 2018-11-04 23:56:42 -06:00
Nathaniel Nicandro
28d4390a1f jupyter-repl-eval-string: Use jupyter-with-message-content 2018-11-04 17:05:44 -06:00
Nathaniel Nicandro
4f40b050df Simplify working with buffers to insert kernel output
* Rename `jupyter-repl-with-output-buffer` to `jupyter-with-output-buffer`.

* Replace uses of `jupyter-repl-with-doc-buffer` with
  `jupyter-with-output-buffer`. The difference between the two was that
  `jupyter-repl-with-doc-buffer` always reset the buffer before inserting new
  output.
2018-11-04 17:05:44 -06:00
Nathaniel Nicandro
55b5f680ec Enable undo in a REPL input cell 2018-11-02 09:14:29 -05:00
Nathaniel Nicandro
b4cdf9de0b jupyter-repl-propertize-output: Also suppress fontification of comments 2018-11-02 09:10:17 -05:00
Nathaniel Nicandro
58e1515e75 Fix beginning-of-buffer error 2018-11-01 21:12:59 -05:00
Nathaniel Nicandro
4f78ef34a2 Add jupyter-repl-insert-message
This function is essentially the same as `jupyter-repl-insert-data` but also
allows different kernel languages to do post-processing to the inserted data.

This is done by defining a new method, `jupyter-repl-after-insert-message`
which is called with the buffer narrowed to the inserted data.

One of its uses is to fontify documentation strings of Python kernels when
making inspect requests.
2018-10-31 18:49:37 -05:00
Nathaniel Nicandro
01be7be844 jupyter-inspect: Ensure the right client is used for `help-setup-xref' 2018-10-31 18:49:37 -05:00
Nathaniel Nicandro
589bfecdb0 jupyter-handle-display-data: Only inhibit redisplay if debug-on-error is nil 2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
b1bbfd0e1a Move python specific traceback handling to jupyter-python.el 2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
cc95092797 jupyter-handle-status: Don't error if a REPL cell is not found
This change is required because when evaluating code in other contexts than the
REPL, the convention is to set `jupyter-inhibit-handlers` to `(not :status)` so
that the `execution-state` can be updated for the mode-line construct.
2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
23caa99670 jupyter-repl-insert-data: Remove code duplication when inserting images 2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
890f5ab3cb Silence byte compiler
* Declare undeclared external functions

* Add ext: prefix to filename of external packages that may not be present on
  every system

* Remove `company-grab-symbol-cons` function declaration since this function is
  no longer used.
2018-10-27 22:16:54 -05:00
Nathaniel Nicandro
2f2ac53851 jupyter-repl-after-change: Mention that cl-call-next-method needs to be called 2018-10-27 22:16:54 -05:00