Skip to content

Commit

Permalink
Support parsing and highlighting REPL input cells with tree-sitter
Browse files Browse the repository at this point in the history
  • Loading branch information
ubolonton committed Jan 12, 2022
1 parent 42a9765 commit 51082f6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions jupyter-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ interpreted as `in'."
;; buffer modified anymore. This is also an indicator for when undo's
;; can be made in the buffer.
(set-buffer-modified-p nil)
;; FIX: Figure out why Emacs hangs if we parse right now.
(when tree-sitter-mode
(run-with-idle-timer 0 nil
(lambda ()
(tree-sitter-resume))))
(setq buffer-undo-list '((t . 0))))
((eq type 'out)
;; Output is normally inserted by first going to the end of the output
Expand Down Expand Up @@ -730,6 +735,14 @@ POS defaults to `point'."
REQ is the `jupyter-request' to associate with the current cell.
Place `point' at `point-max'."
(goto-char (point-max))
(when (and (bound-and-true-p tree-sitter-mode)
(functionp 'tree-sitter-pause))
(tree-sitter-pause))
(when (and (bound-and-true-p tree-sitter-hl-mode)
(functionp 'tree-sitter-hl-dry-up-region))
(tree-sitter-hl-dry-up-region
(jupyter-repl-cell-code-beginning-position)
(jupyter-repl-cell-code-end-position)))
(let ((beg (jupyter-repl-cell-beginning-position))
(count (jupyter-repl-cell-count)))
(jupyter-repl-newline)
Expand Down Expand Up @@ -1731,6 +1744,16 @@ Return the buffer switched to."
(add-hook 'kill-buffer-hook #'jupyter-repl--deactivate-interaction-buffers nil t)
(add-hook 'after-change-functions 'jupyter-repl-do-after-change nil t)
(add-hook 'pre-redisplay-functions 'jupyter-repl-preserve-window-margins nil t)
(setq-local tree-sitter-get-parse-region-function
(lambda ()
;; TODO: Return an empty region when we don't have an input
;; cell ready.
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(cons (jupyter-repl-cell-code-beginning-position)
(jupyter-repl-cell-code-end-position))))))
;; Initialize the REPL
(jupyter-repl-initialize-fontification)
(jupyter-repl-isearch-setup)
Expand Down

0 comments on commit 51082f6

Please sign in to comment.