mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-04 15:41:37 -05:00
Add jupyter-repl-after-change
method
* Rename `jupyter-repl-after-buffer-change` to `julia-repl-do-after-change` * Add the method `jupyter-repl-after-change` which gets called in `jupyter-repl-do-after-change` so that kernel languages can modify the input cell after buffer changes. The default implementation of the method does the work that was previously done in `jupyter-repl-after-buffer-change`
This commit is contained in:
parent
13b92d7d33
commit
a4fab1ff3b
1 changed files with 31 additions and 13 deletions
|
@ -1561,22 +1561,40 @@ more characters than were initially in the buffer."
|
|||
(when (text-property-not-all beg end 'field 'cell-code)
|
||||
(font-lock-fillin-text-property beg end 'field 'cell-code)))
|
||||
|
||||
(defun jupyter-repl-after-buffer-change (beg end len)
|
||||
(defun jupyter-repl-do-after-change (beg end len)
|
||||
"Insert line continuation prompts in `jupyter-repl-mode' buffers.
|
||||
BEG, END, and LEN have the same meaning as in
|
||||
`after-change-functions'."
|
||||
(when (eq major-mode 'jupyter-repl-mode)
|
||||
(cond
|
||||
;; Insertions only
|
||||
((= len 0)
|
||||
(goto-char beg)
|
||||
(when (jupyter-repl-cell-line-p)
|
||||
;; Avoid doing anything on self insertion
|
||||
(unless (and (= (point) (1- end))
|
||||
(not (eq (char-after) ?\n)))
|
||||
(setq end (jupyter-repl-insert-continuation-prompts end)))
|
||||
(jupyter-repl-mark-as-cell-code beg end))
|
||||
(goto-char end)))))
|
||||
(with-demoted-errors "Jupyter error after buffer change: %S"
|
||||
(cond
|
||||
((= len 0)
|
||||
(jupyter-repl-after-change 'insert beg end))
|
||||
((and (= beg end) (not (zerop len)))
|
||||
(jupyter-repl-after-change 'delete beg len))))))
|
||||
|
||||
(cl-defgeneric jupyter-repl-after-change (_type _beg _end-or-len)
|
||||
"Called from the `after-change-functions' of a REPL buffer.
|
||||
Modify the text just inserted or deleted. TYPE is either insert
|
||||
or delete to signify if the change was due to insertion or
|
||||
deletion of text. BEG is always the beginning of the insertion or
|
||||
deletion. END-OR-LEN is the end of the insertion when TYPE is
|
||||
insert and is the length of the deleted text when TYPE is delete.
|
||||
|
||||
The `after-change-functions' of the REPL buffer are only called
|
||||
for changes to input cells and not for output generated by the
|
||||
kernel."
|
||||
nil)
|
||||
|
||||
(cl-defmethod jupyter-repl-after-change ((_type (eql insert)) beg end)
|
||||
(goto-char beg)
|
||||
(when (jupyter-repl-cell-line-p)
|
||||
;; Avoid doing anything on self insertion
|
||||
(unless (and (= (point) (1- end))
|
||||
(not (eq (char-after) ?\n)))
|
||||
(setq end (jupyter-repl-insert-continuation-prompts end)))
|
||||
(jupyter-repl-mark-as-cell-code beg end))
|
||||
(goto-char end))
|
||||
|
||||
(defun jupyter-repl-kill-buffer-query-function ()
|
||||
"Ask before killing a Jupyter REPL buffer.
|
||||
|
@ -2458,7 +2476,7 @@ in the appropriate direction, to the saved element."
|
|||
(erase-buffer)
|
||||
;; Add local hooks
|
||||
(add-hook 'kill-buffer-query-functions #'jupyter-repl-kill-buffer-query-function nil t)
|
||||
(add-hook 'after-change-functions 'jupyter-repl-after-buffer-change 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)
|
||||
;; Initialize the REPL
|
||||
(buffer-disable-undo)
|
||||
|
|
Loading…
Add table
Reference in a new issue