Closed zauberen closed 1 month ago
I can't remember hitting this so I'm not convinced there's an issue but I'll try and look into it when I can.
Sure, I've thrown together a minimal configuration to reproduce the bug in emacs 29.4 if that helps.
Steps:
emacs --init-dir .emacs.d.test
Com
then M-x yasnippet-capf
. This just completes the name of the snippet, reproducing the bug.defun
which works as expected.;;; init.el --- Test emacs config
;;; Commentary:
;;; Minimal test environment with package.el
;;; Code:
;; Package management ;;
(require 'package)
(setq package-selected-packages
'( use-package ))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(eval-when-compile
(package-install-selected-packages t)
(require 'use-package))
;; Add fido to make m-x completion easier
(fido-mode)
(use-package yasnippet-snippets
:ensure t)
(use-package yasnippet
:ensure t
:after yasnippet-snippets
:config
(yas-global-mode 1))
(use-package cape
:ensure t)
(use-package corfu
:ensure t
:after cape
:config
(global-corfu-mode))
(use-package yasnippet-capf
:after cape
:ensure t
:config
(add-to-list 'completion-at-point-functions #'yasnippet-capf)
(setq yasnippet-capf-lookup-by 'name))
;;; init.el ends here
The configuration for the test snippet can be found here: https://github.com/AndreaCrotti/yasnippet-snippets/blob/1bf034887c4048c38266842686b7f9c8384f72e7/snippets/emacs-lisp-mode/word-or-region
This snippet works fine with yas-insert-snippet
or yas-expand
on word-or-region
and it works in my PR.
Type in Com then M-x yasnippet-capf.
Ah, so that's the issue. If you want to call something from M-x
then just call yas-expand
itself. I can repro this but that's exactly why it shouldn't be used. I can't get it to trigger any other way using your init, but I'll merge it anyway.
The problem is that if the key and name are not the same, when the capf runs
yas-expand
on exit nothing happens.I am using
yasnippet-snippets
for my snippets, so in java I have a snippet with a name ofprintln
and a key ofpr
. If I type inpr
and callyas-expand
, the snippet works. If I type inprintln
and callyas-expand
it does not.I have a fix to this, will open a PR later today.