From 29ec1f40f39df0ff3e77d3e73c6cb15d8883fcd3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 3 Jul 2025 15:43:59 +0200 Subject: [PATCH] feat(org): jupyter-repl: move cursor to prompt on self-insert-command Ala 3384414, but for jupyter-repl, which isn't a comint-derived. Ref: 3384414e957f --- modules/lang/org/contrib/jupyter.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/lang/org/contrib/jupyter.el b/modules/lang/org/contrib/jupyter.el index acb8be0ad..9fe24691f 100644 --- a/modules/lang/org/contrib/jupyter.el +++ b/modules/lang/org/contrib/jupyter.el @@ -1,5 +1,26 @@ ;;; lang/org/contrib/jupyter.el -*- lexical-binding: t; -*- ;;;###if (modulep! +jupyter) +;; TODO: Move to :tools jupyter + +(use-package! jupyter-repl + :defer t + :config + ;; HACK: If the user is anywhere but the last prompt, typing should move them + ;; there instead of unhelpfully spewing read-only errors at them. + ;; REVIEW: Upstream this (maybe?) + (defun +jupyter--move-cursor-to-prompt-h () + (and (eq this-command 'self-insert-command) + (> (save-excursion + (goto-char (point-max)) + (jupyter-repl-cell-code-beginning-position)) + (point)) + (goto-char (point-max)))) + + (add-hook! 'jupyter-repl-mode-hook + (defun +jupyter--init-move-cursor-to-prompt-h () + (add-hook 'pre-command-hook #'+jupyter--move-cursor-to-prompt-h + nil t)))) + (use-package! ob-jupyter :defer t