Skip to content

Commit b65cc47

Browse files
committed
Support parsing and highlighting REPL input cells with tree-sitter
1 parent 42a9765 commit b65cc47

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

jupyter-repl.el

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ interpreted as `in'."
423423
;; buffer modified anymore. This is also an indicator for when undo's
424424
;; can be made in the buffer.
425425
(set-buffer-modified-p nil)
426+
;; FIX: Figure out why Emacs hangs if we parse right now.
427+
(when tree-sitter-mode
428+
(run-with-idle-timer 0 nil
429+
(lambda ()
430+
(tree-sitter-resume))))
426431
(setq buffer-undo-list '((t . 0))))
427432
((eq type 'out)
428433
;; Output is normally inserted by first going to the end of the output
@@ -730,6 +735,14 @@ POS defaults to `point'."
730735
REQ is the `jupyter-request' to associate with the current cell.
731736
Place `point' at `point-max'."
732737
(goto-char (point-max))
738+
(when (and (bound-and-true-p tree-sitter-mode)
739+
(functionp 'tree-sitter-pause))
740+
(tree-sitter-pause))
741+
(when (and (bound-and-true-p tree-sitter-hl-mode)
742+
(functionp 'tree-sitter-hl-dry-up-region))
743+
(tree-sitter-hl-dry-up-region
744+
(jupyter-repl-cell-code-beginning-position)
745+
(jupyter-repl-cell-code-end-position)))
733746
(let ((beg (jupyter-repl-cell-beginning-position))
734747
(count (jupyter-repl-cell-count)))
735748
(jupyter-repl-newline)
@@ -1731,6 +1744,14 @@ Return the buffer switched to."
17311744
(add-hook 'kill-buffer-hook #'jupyter-repl--deactivate-interaction-buffers nil t)
17321745
(add-hook 'after-change-functions 'jupyter-repl-do-after-change nil t)
17331746
(add-hook 'pre-redisplay-functions 'jupyter-repl-preserve-window-margins nil t)
1747+
(setq-local tree-sitter-get-parse-region-function
1748+
(lambda ()
1749+
;; TODO: Return an empty region when we don't have an input
1750+
;; cell ready.
1751+
(save-excursion
1752+
(goto-char (point-max))
1753+
(cons (jupyter-repl-cell-code-beginning-position)
1754+
(jupyter-repl-cell-code-end-position)))))
17341755
;; Initialize the REPL
17351756
(jupyter-repl-initialize-fontification)
17361757
(jupyter-repl-isearch-setup)

0 commit comments

Comments
 (0)