This replaces the `jupyter-repl--handle-payload` function and allows payloads
to be handled in other contexts than the REPL, for example inserting a new
source block when receiving a set_next_input payload for the `org-mode` client.
Uses the new function `jupyter-repl-font-lock-fontify-region` to fontify a REPL
buffer. This function will only fontify regions corresponding to input cells
and excludes all other regions from fontification. Regions besides input cells
correspond mainly to output from the kernel and use font-lock-face to fontify
their contents.
This allows us to remove the functions and variables related to adding syntax
properties to the output of a cell since these were previously used to avoid
syntactic fontification of the output.
Adds `jupyter-repl--syntax-propertize` which generalizes the old
`syntax-propertize-function` to handle regions containing both cell code and
cell output.
In Emacs, the end position of a region is exclusive. So functions like
`delete-region` will delete the entire region specified excluding the end
position. Follow this convention with the cell code position.
This fixes issues when adding syntax properties to a cell's code. See
`jupyter-repl-initialize-fontification`.
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.
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.
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.
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.
* 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.
* 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.
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.
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`.
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.
* 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`.
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.
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`
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.