Add more documentation, clean up comments

This commit is contained in:
Nathaniel Nicandro 2018-01-04 17:21:59 -06:00
parent 2c942fd0b7
commit 2d0ef56be6
2 changed files with 23 additions and 13 deletions

View file

@ -662,6 +662,7 @@ for the heartbeat channel."
;; `jupyter-idle-received-p' property is non-nil, then it signifies that the ;; `jupyter-idle-received-p' property is non-nil, then it signifies that the
;; request has been handled by the kernel. ;; request has been handled by the kernel.
(cl-defstruct jupyter-request (cl-defstruct jupyter-request
;; NOTE Use `jupyter-request-id' instead of `jupyter-request--id'
(-id) (-id)
(time (current-time)) (time (current-time))
(idle-received-p nil) (idle-received-p nil)
@ -669,6 +670,7 @@ for the heartbeat channel."
(callbacks)) (callbacks))
(defun jupyter-request-id (req) (defun jupyter-request-id (req)
"Get the message ID for REQ."
(with-timeout (0.5 (error "Request not processed.")) (with-timeout (0.5 (error "Request not processed."))
(while (null (jupyter-request--id req)) (while (null (jupyter-request--id req))
(sleep-for 0 10))) (sleep-for 0 10)))
@ -676,7 +678,7 @@ for the heartbeat channel."
(defun jupyter-request-inhibit-handlers (req) (defun jupyter-request-inhibit-handlers (req)
"Inhibit the execution of a `jupyter-kernel-client's handlers for REQ. "Inhibit the execution of a `jupyter-kernel-client's handlers for REQ.
Set `jupyter-request-run-handlers-p' to nil for REQ and return Sets `jupyter-request-run-handlers-p' to nil for REQ and returns
REQ. This function is intended to be a convenience function so REQ. This function is intended to be a convenience function so
that you can do: that you can do:
@ -704,14 +706,14 @@ FUNCTION on when messages of that type are received for REQ. The
symbol should be the same as one of the message types which are symbol should be the same as one of the message types which are
expected to be received from a kernel where underscore characters expected to be received from a kernel where underscore characters
are replaced with hyphens, see are replaced with hyphens, see
http://jupyter-client.readthedocs.io/en/latest/messaging.html. So http://jupyter-client.readthedocs.io/en/latest/messaging.html.
to add a callback which fires for and \"execute_reply\", MSG-TYPE
should be the symbol `execute-reply'. As a special case if
MSG-TYPE is t, FUNCTION is run for all received messages of REQ.
If MSG-TYPE is a list, then it should be a list of symbols as So to add a callback which fires for an \"execute_reply\",
described above. FUNCTION will then run for every type of message MSG-TYPE should be the symbol `execute-reply'. As a special case
in the list. if MSG-TYPE is t, FUNCTION is run for all received messages of
REQ. If MSG-TYPE is a list, then it should be a list of symbols
as described above. FUNCTION will then run for every type of
message in the list.
REQ is a `jupyter-request' object as returned by the kernel REQ is a `jupyter-request' object as returned by the kernel
request methods of a `jupyter-kernel-client'. request methods of a `jupyter-kernel-client'.
@ -777,7 +779,6 @@ defaults to 1 second."
(defun jupyter-wait-until-idle (req &optional timeout) (defun jupyter-wait-until-idle (req &optional timeout)
"Wait until TIMEOUT for REQ to receive an idle message. "Wait until TIMEOUT for REQ to receive an idle message.
If TIMEOUT is non-nil, it defaults to 1 second." If TIMEOUT is non-nil, it defaults to 1 second."
(jupyter-wait-until 'status req timeout #'jupyter-message-status-idle-p)) (jupyter-wait-until 'status req timeout #'jupyter-message-status-idle-p))
@ -828,7 +829,6 @@ are taken:
`jupyter-handle-execute-result', `jupyter-handle-execute-result',
`jupyter-handle-kernel-info-reply', ... `jupyter-handle-kernel-info-reply', ...
- Cleanup request when kernel is done processing it" - Cleanup request when kernel is done processing it"
(when (jupyter-channel-messages-available-p channel) (when (jupyter-channel-messages-available-p channel)
(let* ((msg (jupyter-channel-get-message channel)) (let* ((msg (jupyter-channel-get-message channel))
(pmsg-id (jupyter-message-parent-id msg)) (pmsg-id (jupyter-message-parent-id msg))
@ -851,8 +851,6 @@ are taken:
(remhash pmsg-id requests)))))) (remhash pmsg-id requests))))))
(run-with-timer 0.005 nil #'jupyter-handle-message client channel))) (run-with-timer 0.005 nil #'jupyter-handle-message client channel)))
;;; Received message handlers
;;; STDIN message requests/handlers ;;; STDIN message requests/handlers
(cl-defmethod jupyter-handle-message ((channel jupyter-stdin-channel) (cl-defmethod jupyter-handle-message ((channel jupyter-stdin-channel)

View file

@ -177,9 +177,11 @@ can contain the following keywords along with their values:
args)))) args))))
(defun jupyter-repl-newline () (defun jupyter-repl-newline ()
"Insert a read-only newline into the `current-buffer'."
(jupyter-repl-insert "\n")) (jupyter-repl-insert "\n"))
(defun jupyter-repl-insert-html (html) (defun jupyter-repl-insert-html (html)
"Parse and insert the HTML string using `shr-insert-document'."
(let ((start (point))) (let ((start (point)))
(shr-insert-document (shr-insert-document
(with-temp-buffer (with-temp-buffer
@ -188,6 +190,10 @@ can contain the following keywords along with their values:
(add-text-properties start (point) '(read-only t)))) (add-text-properties start (point) '(read-only t))))
(defun jupyter-repl-insert-latex (tex) (defun jupyter-repl-insert-latex (tex)
"Generate and insert a LaTeX image based on TEX.
Note that this uses `org-format-latex' to generate the LaTeX
image."
(require 'org) (require 'org)
(let (beg end) (let (beg end)
(setq beg (point)) (setq beg (point))
@ -774,17 +780,23 @@ The first character of the cell code corresponds to position 1."
(add-hook 'after-change-functions 'jupyter-repl-after-buffer-change nil t)) (add-hook 'after-change-functions 'jupyter-repl-after-buffer-change nil t))
(defun jupyter-repl-initialize-fontification (ext) (defun jupyter-repl-initialize-fontification (ext)
"Enable `font-lock-mode' based on the mode corresponding to EXT.
EXT should be a file extension, including the '.', and the mode
enabled will be the one of those registered in
`auto-mode-alist'."
(let (fld) (let (fld)
(with-jupyter-repl-lang-buffer (with-jupyter-repl-lang-buffer
(setq buffer-file-name (concat "jupyter-repl-lang" ext)) (setq buffer-file-name (concat "jupyter-repl-lang" ext))
(set-auto-mode) (set-auto-mode)
(setq buffer-file-name nil) (setq buffer-file-name nil)
(setq fld font-lock-defaults)) (setq fld font-lock-defaults))
;; Set the `font-lock-defaults' to those of the REPL language
(setq font-lock-defaults fld) (setq font-lock-defaults fld)
(font-lock-mode))) (font-lock-mode)))
(defun jupyter-repl-insert-banner (banner) (defun jupyter-repl-insert-banner (banner)
"Insert BANNER into the `current-buffer'.
Make the text of BANNER read only and apply the `shadow' face to
it."
(let ((start (point)) (let ((start (point))
(inhibit-modification-hooks t)) (inhibit-modification-hooks t))
(jupyter-repl-insert banner) (jupyter-repl-insert banner)