elken / yasnippet-capf

Completion-At-Point Extension for YASnippet
GNU General Public License v3.0
40 stars 9 forks source link

Completions are nil for snippets #21

Closed thorstengrothe closed 4 months ago

thorstengrothe commented 4 months ago

Hi,

I like your package very much and use it every day. When I type a name of my snippet in the buffer it looks like this

yasnippet

For dabbrev it looks fine see here

Dabbrev

Do you have an idea, what's going wrong?

Regards Thorsten

thorstengrothe commented 4 months ago

And another thing, if I press return, nothing happens. It worked in the past and I have no clue, what is going wrong. This is my config

(use-package corfu
  :ensure t
  ;; :defer t
  :bind (:map corfu-map
              ;; ("M-SPC"      . corfu-insert-separator)
              ("M-k"        . corfu-next)
              ("M-i"        . corfu-previous)
              ;; ([backtab]    . corfu-previous)
              ;; ("S-<return>" . nil)
              ;; leave my entry as it is
              ("RET"        . corfu-expand))
  :custom
  (corfu-cycle t)               
  (corfu-auto t)                 
  (corfu-separator ?\s)        
  (corfu-quit-no-match 'separator)
  :init
  (global-corfu-mode)
  :hook (before-save-hook . corfu-quit)
  :config
  (require 'corfu-history)
  (corfu-history-mode 1)
  (corfu-popupinfo-mode)
  (savehist-mode 1)
  (add-to-list 'savehist-additional-variables 'corfu-history)
  )
(use-package cape
  :ensure t
  :after corfu
  :config
  (defun thor-cape-capf-setup-elisp ()
    (let ((result))
      (dolist (element '(cape-file cape-dabbrev) result)
        (add-to-list 'completion-at-point-functions element))))

  (defun thor-cape-capf-setup-latex ()
    (let ((result))
      (dolist (element '(cape-file cape-dabbrev cape-tex) result)
        (add-to-list 'completion-at-point-functions element))))
  :hook
  (emacs-lisp-mode . thor-cape-capf-setup-elisp)
  (latex-mode . thor-cape-capf-setup-latex)
  (tex-mode . thor-cape-capf-setup-latex)
  )

(use-package yasnippet-capf
  :ensure (yasnippet-capf :type git :host github :repo "elken/yasnippet-capf")
  :after cape
  :init
  (add-to-list 'completion-at-point-functions #'yasnippet-capf)
  :config
  (setq yasnippet-capf-lookup-by 'name) ;; Prefer the name of the snippet instead
  )

sorry for the double post :-)

elken commented 4 months ago

Hi,

I like your package very much and use it every day.

Thanks very much :smile:

Do you have an idea, what's going wrong?

Either the snippets you're using or have written are missing fields, or something has changed upstream in yasnippet. What do those hydra-* snippets look like?

EDIT: Actually I might have an idea what this is, don't think it's on your end after all. Watch this space :smile: Do still send the snippets though, just in case it is that

elken commented 4 months ago

Just pushed a fix that should fallback to resolve the first issue, but I do now suspect that improperly defined snippets are causing the second.

thorstengrothe commented 4 months ago

Thanks for the super fast response. I updated the package with elpaca now it looks like this:

hydranew

I can see them but both snippets are not expandable when I press RET or SPACE

The hydra snippets look like this

# -*- mode: snippet -*-
#name : hydra
#key : hydra
#contributor : Thorsten Grothe
# --
(defhydra my/hydra-${1:name} (:color blue :hint nil)
"
"
("${2:letter}" ${3:command} "${4:Text}" :column "${5:column name}")

("q" nil "quit")
)

and

# -*- mode: snippet -*-
#name : hydra-spalte
#key : hydra
#contributor : Thorsten Grothe
# --
"${1:Titel Spalte}"
(
("$" ${2:Befehl} "${3:Name")

)
thorstengrothe commented 4 months ago

Deleted the emacs-lisp-mode dir under snippets and made a new one

# -*- mode: snippet -*-
# name: defun
# key: defun
# --
(defun ${1:name} ()
  "${2:Describe function}"
  (interactive)
  (some-command)
  (some-other-command)
  )

Closed emacs and reopen an *.el file. Typed defun and nothing happens, the snippet not appears on the in buffer popup. Hm, strange....

Thanks for your help!

elken commented 4 months ago

Thanks for the super fast response. I updated the package with elpaca now it looks like this:

hydranew

I can see them but both snippets are not expandable when I press RET or SPACE

The hydra snippets look like this

# -*- mode: snippet -*-
#name : hydra
#key : hydra
#contributor : Thorsten Grothe
# --
(defhydra my/hydra-${1:name} (:color blue :hint nil)
"
"
("${2:letter}" ${3:command} "${4:Text}" :column "${5:column name}")

("q" nil "quit")
)

and

# -*- mode: snippet -*-
#name : hydra-spalte
#key : hydra
#contributor : Thorsten Grothe
# --
"${1:Titel Spalte}"
(
("$" ${2:Befehl} "${3:Name")

)

Imagine with these you need a space between the # and the key name.

As for the second issue, you might have to call M-x yas-reload-all first.

thorstengrothe commented 4 months ago

Imagine with these you need a space between the # and the key name.

As for the second issue, you might have to call M-x yas-reload-all first.

I fixed the space in all my snippets and reloaded everything. It helps nothing it does not work. Now I get no popup completion in my buffer and can expand nothing. Hm, something is going wrong here 😊

elken commented 4 months ago

I can't reproduce this. Have included a webm demo below with one of your snippets saved as below

# -*- mode: snippet -*-
# name : hydra
# key : hydra
# --
(defhydra my/hydra-${1:name} (:color blue :hint nil)
"
"
("${2:letter}" ${3:command} "${4:Text}" :column "${5:column name}")

("q" nil "quit")
)

Screencast from 2024-04-20 19-12-01.webm

Sounds like you've perhaps got issues with your yasnippet setup in that case :frowning_face:

thorstengrothe commented 4 months ago

Thank you, I see. I believe I got something.

When I type the name of the snippet and hit TAB nothing happens. When I thereafter hit M-X and call yasnippet-capf in the minibuffer I got the popups showing me snippets.

Now I can hit TAB and the snippet is expanding. So I guess it has something to do with the keybinding. In Cape I set :bind (("<tab>" . completion-at-point).

In Yasnippet-Capf I set nothing, is this the problem?

elken commented 4 months ago

No, all the package does is feed the data into Corfu so it can complete it as normal.

Corfu already maps <tab> as needed, so unless you have a specific reason to bind that globally then I would probably say don't.

thorstengrothe commented 4 months ago

Ok I setup my packages to a minimum

Vertico, consult and orderless are disabled.

(use-package yasnippet
  :commands (yas-global-mode)
  :init
  (yas-global-mode)
  :config
  (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
  )
(use-package corfu
  :ensure t
  )

(use-package cape
  :ensure t
  :after corfu
  )

(use-package yasnippet-capf
  :ensure (yasnippet-capf :type git :host github :repo "elken/yasnippet-capf")
  :after cape
  :init
  (add-to-list 'completion-at-point-functions #'yasnippet-capf)
  :config
  (setq yasnippet-capf-lookup-by 'name) ;; Prefer the name of the snippet instead
  )

I setup two snippets for emacs-lisp-mode in a new empty snippet dir.

# -*- mode: snippet -*-
# name: lorem
# key: lorem
# --
blabkla

# -*- mode: snippet -*-
# name: test
# key: test
# --
test lorem lorem lorem lorem

Open an *.el file

Enter test --> snippet expands Enter lorem --> snippet expands

But without popup in my file, it expands silently, nothing else. What I want is a popup in my buffer like in your small video.

Hm, what I'm doing wrong?

elken commented 4 months ago

I don't know, but it seems like the issue is with your config which unfortunately I can't debug.

If you're able to find a reproducible case that proves this package is at fault then please do submit another issue, otherwise I think this one can be closed for now.