Add jupyter-completion-post-completion method

This way kernel languages can override the default behavior. The default
implementation expands the candidate snippet if one is available.
This commit is contained in:
Nathaniel Nicandro 2018-10-23 20:21:04 -05:00
parent 8ccd41fe89
commit ab44407fdf

View file

@ -2030,16 +2030,22 @@ Use the `company-doc-buffer' to insert the results."
(defun jupyter-completion--post-completion (arg status) (defun jupyter-completion--post-completion (arg status)
"If ARG is a completion with a snippet, expand the snippet. "If ARG is a completion with a snippet, expand the snippet.
Do this only if STATUS is sole or finished." Do this only if STATUS is sole or finished."
(when (and (memq status '(sole finished)) (when (memq status '(sole finished))
(get-text-property 0 'snippet arg)) (jupyter-completion-post-completion arg)))
(when (and (require 'yasnippet nil t)
(not yas-minor-mode)) (cl-defgeneric jupyter-completion-post-completion (candidate)
"Called when CANDIDATE was selected as the completion candidate.
The default implementation expands the snippet in CANDIDATE's
snippet text property, if any, and if `yasnippet' is available."
(when (and (get-text-property 0 'snippet candidate)
(require 'yasnippet nil t))
(unless yas-minor-mode
(yas-minor-mode 1)) (yas-minor-mode 1))
;; Due to packages like smartparens ;; Due to packages like smartparens
(when (eq (char-after) ?\)) (when (eq (char-after) ?\))
(delete-char 1)) (delete-char 1))
(yas-expand-snippet (yas-expand-snippet
(get-text-property 0 'snippet arg) (get-text-property 0 'snippet candidate)
(save-excursion (save-excursion
(forward-sexp -1) (forward-sexp -1)
(point)) (point))