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.
This commit is contained in:
Nathaniel Nicandro 2018-11-09 22:59:24 -06:00
parent 092b7f9853
commit e01f8df624
2 changed files with 26 additions and 49 deletions

View file

@ -54,26 +54,31 @@ buffer."
(jupyter-repl-insert
(make-string (if (> len 4) len 4) ? ))))))))
(cl-defmethod jupyter-repl-after-insert-message (type mime &context (jupyter-lang python))
(cl-defmethod jupyter-insert :around ((msg cons)
&context (jupyter-lang python)
&rest _)
"Fontify docstrings after inserting inspect messages."
(let ((mime (cl-call-next-method)))
(prog1 mime
(cond
((and (eq type :inspect-reply)
(eq mime :text/plain))
((and (eq mime :text/plain)
(eq (jupyter-message-type msg) :inspect-reply))
(when (search-forward "Docstring:" nil t)
(let ((mode major-mode))
(with-current-buffer (make-indirect-buffer (current-buffer) " *jupyter-python-temp*")
(with-current-buffer
(make-indirect-buffer (current-buffer) " *jupyter-python-temp*")
(save-restriction
(narrow-to-region (1+ (point)) (point-max))
(delay-mode-hooks (rst-mode))
;; NOTE: We get the font-lock-fontified property for free since
;; `ansi-color-apply' already inserts it for :text/plain messages,
;; thus there is no need to call
;; `jupyter-repl-fixup-font-lock-properties' after
;; `ansi-color-apply' already inserts it for :text/plain
;; messages, thus there is no need to call
;; `jupyter-fixup-font-lock-properties' after
;; `font-lock-ensure'
(font-lock-ensure))
(kill-buffer))
(funcall mode))))
(t nil)))
(t nil)))))
(cl-defmethod jupyter-load-file-code (file &context (jupyter-lang python))
(concat "%run " file))

View file

@ -392,34 +392,6 @@ Do this only when the `major-mode' is `jupyter-repl-mode'."
&optional _metadata)
(jupyter-widgets-display-model jupyter-current-client (plist-get data :model_id)))
(defun jupyter-repl-insert-message (msg)
"Insert a messages contents in the current buffer.
MSG is the message to be inserted. A message is inserted only if
its content has a status key of \"ok\" and has a found key of t.
Calls the method `jupyter-repl-after-insert-message', if the
message was inserted."
(jupyter-with-message-content msg
(status found)
(when (and (equal status "ok") (eq found t))
(let ((beg (point))
(mime (jupyter-insert (jupyter-message-content msg))))
(when mime
(save-excursion
(save-restriction
(narrow-to-region beg (point))
(goto-char beg)
(jupyter-repl-after-insert-message
(jupyter-message-type msg) mime))))))))
(cl-defgeneric jupyter-repl-after-insert-message (_type _mime)
"Called after a message has been inserted for certain message types.
If a message with TYPE causes output to be inserted into a
buffer, the buffer is narrowed to the inserted output before this
function is called. MIME will be the mimetype of the data
inserted."
(ignore))
;;; Prompt
(defun jupyter-repl--prompt-display-value (str face)
@ -1739,7 +1711,7 @@ DETAIL is the detail level to use for the request and defaults to
(inhibit-read-only t))
(if (buffer-live-p buffer)
(with-current-buffer buffer
(jupyter-repl-insert-message msg)
(jupyter-insert (jupyter-message-content msg))
(current-buffer))
(with-help-window (help-buffer)
(with-current-buffer standard-output
@ -1749,7 +1721,7 @@ DETAIL is the detail level to use for the request and defaults to
(lambda () (jupyter-inspect code pos nil detail))))
nil)
(setq jupyter-current-client client)
(jupyter-repl-insert-message msg)))))
(jupyter-insert (jupyter-message-content msg))))))
(message "Nothing found for %s"
(with-temp-buffer
(insert code)