mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
fix(completion/copilot): custom accept fun ignoring trailing "{" chars
In languages that uses "{" for blocks, accepting a Copilot completion
that ends with "{", causing a structural imbalance, which
structural-based packages like smartparens does not like and causes
headaches.
With the custom accept function, trailing "{" chars along with any
whitespace before it, are ignored from Copilot completion. An exception
is made for if the removal of trailing "{" and whitespace yields an
empty completion, in which case the completion is accepted as is.
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
(prog-mode . copilot-mode)
|
||||
|
||||
:general
|
||||
("C-<tab>" 'siren-copilot-accept-completion-dwim)
|
||||
("<backtab>" 'siren-copilot-accept-completion-dwim)
|
||||
("C-<tab>" 'siren-copilot-accept-completion-without-trailing-opening-curly-bracket-dwim)
|
||||
("<backtab>" 'siren-copilot-accept-completion-without-trailing-opening-curly-bracket-dwim)
|
||||
("M-F" 'siren-copilot-accept-completion-by-word-dwim)
|
||||
("M-E" 'siren-copilot-accept-completion-by-line-dwim)
|
||||
(:keymaps 'copilot-completion-map
|
||||
@@ -43,6 +43,20 @@
|
||||
(apply f args)
|
||||
(copilot-complete)))
|
||||
|
||||
(defun siren-copilot-accept-completion-without-trailing-opening-curly-bracket-dwim ()
|
||||
"Accept the current completion or trigger copilot-compilot."
|
||||
(interactive)
|
||||
(siren-copilot-complete-or-call 'siren-copilot-accept-completion-without-trailing-opening-curly-bracket))
|
||||
|
||||
(defun siren-copilot-accept-completion-without-trailing-opening-curly-bracket ()
|
||||
"Accept completion removing ` {' or `{' from the end of the completion."
|
||||
(interactive)
|
||||
(copilot-accept-completion (lambda (completion)
|
||||
(let ((index (string-match-p "\s*{\\'" completion)))
|
||||
(if (and index (> index 0))
|
||||
(substring completion 0 index)
|
||||
completion)))))
|
||||
|
||||
:config
|
||||
(with-eval-after-load 'company
|
||||
;; Use company popup even when there's only one result
|
||||
|
||||
Reference in New Issue
Block a user