mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-04 15:41:37 -05:00
Define jupyter-completion-prefix
as a method to use it in different contexts
This commit is contained in:
parent
34aaaf2a66
commit
d1588b2fd9
2 changed files with 37 additions and 1 deletions
|
@ -161,6 +161,31 @@ METADATA has the same meaning as in
|
|||
|
||||
|
||||
;;; Completions in code blocks
|
||||
|
||||
(cl-defmethod jupyter-completion-prefix (&context (major-mode org-mode))
|
||||
(when (org-in-src-block-p 'inside)
|
||||
(let* ((el (org-element-at-point))
|
||||
(lang (org-element-property :language el))
|
||||
info params syntax client)
|
||||
(when (string-prefix-p "jupyter-" lang)
|
||||
(setq info (org-babel-get-src-block-info el)
|
||||
params (nth 2 info)
|
||||
client (with-current-buffer
|
||||
(org-babel-jupyter-initiate-session
|
||||
(alist-get :session params) params)
|
||||
(setq syntax (syntax-table))
|
||||
jupyter-repl-current-client))
|
||||
;; KLUDGE: Remove the need for setting
|
||||
;; `jupyter-repl-current-client', its needed so
|
||||
;; that `jupyter-completion-prefetch' will use the
|
||||
;; right client, similarly for the less specialized
|
||||
;; `jupyter-completion-prefix'
|
||||
(setq jupyter-repl-current-client client)
|
||||
;; Use the syntax table of the language when
|
||||
;; retrieving the prefix
|
||||
(with-syntax-table syntax
|
||||
(cl-call-next-method))))))
|
||||
|
||||
(cl-defmethod jupyter-code-context ((_type (eql inspect))
|
||||
&context (major-mode org-mode))
|
||||
(when (org-in-src-block-p 'inside)
|
||||
|
|
|
@ -1631,8 +1631,15 @@ Works for Julia and Python."
|
|||
(list (jupyter-repl-cell-code)
|
||||
(1- (jupyter-repl-cell-code-position))))
|
||||
|
||||
(defun jupyter-completion-prefix ()
|
||||
(cl-defgeneric jupyter-completion-prefix ()
|
||||
"Return the prefix for the current completion context.
|
||||
This default function checks to see if the
|
||||
`jupyter-kernel-language' of the `jupyter-repl-current-client'
|
||||
has a `:completion-prefix' support function set by
|
||||
`jupyter-kernel-support-put' and calls that function to obtain
|
||||
the completion prefix. If the language does not have a completion
|
||||
prefix function, `jupyter-completion-grab-symbol-cons' is used.
|
||||
|
||||
Note that the prefix returned is not the content sent to the
|
||||
kernel, but the symbol at `point'. See
|
||||
`jupyter-code-context-at-point' for what is actually sent."
|
||||
|
@ -1656,6 +1663,10 @@ kernel, but the symbol at `point'. See
|
|||
(jupyter-completion-floating-point-p))
|
||||
s))))))))
|
||||
|
||||
(cl-defmethod jupyter-completion-prefix (&context (major-mode jupyter-repl-mode))
|
||||
(and (not (get-text-property (point) 'read-only))
|
||||
(cl-call-next-method)))
|
||||
|
||||
(defun jupyter-completion-construct-candidates (matches metadata)
|
||||
"Construct candidates for completion.
|
||||
MATCHES are the completion matches returned by the kernel,
|
||||
|
|
Loading…
Add table
Reference in a new issue