Be clearer in REPL history functions

This commit is contained in:
Nathaniel Nicandro 2018-12-06 00:06:59 -06:00
parent 7f5c8d8a4b
commit 747e82fc22
No known key found for this signature in database
GPG key ID: C34814B309DD06B8

View file

@ -909,8 +909,7 @@ element in that direction relative to the current REPL history.
If the sentinel value is found before rotating N times, return If the sentinel value is found before rotating N times, return
nil." nil."
(if (> n 0) (if (> n 0)
(if (eq (ring-ref jupyter-repl-history -1) 'jupyter-repl-history) (unless (eq (ring-ref jupyter-repl-history -1) 'jupyter-repl-history)
nil
(ring-insert jupyter-repl-history (ring-insert jupyter-repl-history
(ring-remove jupyter-repl-history -1)) (ring-remove jupyter-repl-history -1))
(jupyter-repl-history--next (1- n))) (jupyter-repl-history--next (1- n)))
@ -926,15 +925,14 @@ older history elements."
(or n (setq n 1)) (or n (setq n 1))
(if (< n 0) (jupyter-repl-history-previous (- n)) (if (< n 0) (jupyter-repl-history-previous (- n))
(goto-char (point-max)) (goto-char (point-max))
(let ((elem (jupyter-repl-history--next n))) (let ((code (jupyter-repl-history--next n)))
(if (and (null elem) (equal (jupyter-repl-cell-code) "")) (if (and (null code) (equal (jupyter-repl-cell-code) ""))
(error "End of history") (error "End of history")
(if (null elem) (if (null code)
;; When we have reached the last history element in the forward ;; When we have reached the last history element in the forward
;; direction and the cell code is not empty, make it empty. ;; direction and the cell code is not empty, make it empty.
(jupyter-repl-replace-cell-code "") (jupyter-repl-replace-cell-code "")
(jupyter-repl-replace-cell-code (jupyter-repl-replace-cell-code code))))))
(ring-ref jupyter-repl-history 0)))))))
(defun jupyter-repl-history--previous (n) (defun jupyter-repl-history--previous (n)
"Helper function for `jupyter-repl-history-previous'. "Helper function for `jupyter-repl-history-previous'.
@ -944,8 +942,7 @@ element in that direction relative to the current REPL history.
If the sentinel value is found before rotating N times, return If the sentinel value is found before rotating N times, return
nil." nil."
(if (> n 0) (if (> n 0)
(if (eq (ring-ref jupyter-repl-history 1) 'jupyter-repl-history) (unless (eq (ring-ref jupyter-repl-history 1) 'jupyter-repl-history)
nil
(ring-insert-at-beginning (ring-insert-at-beginning
jupyter-repl-history (ring-remove jupyter-repl-history 0)) jupyter-repl-history (ring-remove jupyter-repl-history 0))
(jupyter-repl-history--previous (1- n))) (jupyter-repl-history--previous (1- n)))
@ -964,11 +961,10 @@ elements."
(unless (equal (jupyter-repl-cell-code) (unless (equal (jupyter-repl-cell-code)
(ring-ref jupyter-repl-history 0)) (ring-ref jupyter-repl-history 0))
(setq n (1- n))) (setq n (1- n)))
(let ((elem (jupyter-repl-history--previous n))) (let ((code (jupyter-repl-history--previous n)))
(if (null elem) (if (null code)
(error "Beginning of history") (error "Beginning of history")
(jupyter-repl-replace-cell-code (jupyter-repl-replace-cell-code code)))))
(ring-ref jupyter-repl-history 0))))))
(cl-defmethod jupyter-handle-history-reply ((client jupyter-repl-client) _req history) (cl-defmethod jupyter-handle-history-reply ((client jupyter-repl-client) _req history)
(jupyter-with-repl-buffer client (jupyter-with-repl-buffer client