0

I've experienced this issue for some time. It's not a blocker but it is a bit annoying.

Steps to reproduce:

Select a region that you want to extract into YASnippet snippet("foo bar"). Eval yas-new-snippet.

You are redirected to a new buffer +new-snippet+ with the following content:

# -*- mode: snippet -*-
# name: 
# key: 
# --
// foo bar
// foo bar

Expected behavior:

# -*- mode: snippet -*-
# name: 
# key: 
# --
// foo bar

pkg-info-package-version yasnippet 20200604.246

4
  • 1
    I'm using the same version of yas and have the correct behavior. You may need to find more about what in you config is causing this before anyone can give any advice.
    – JJPandari
    Oct 28 '20 at 3:56
  • @PanJunjie潘俊杰 thanks for the input. I'll continue investigating it, it could probably be something that activates it twice in my emacs/spacemacs config. Oct 28 '20 at 10:31
  • 1
    You could edebug-defun function yas-new-snippet to find the reasons. On my config yas-new-snippet is working like expected.
    – jue
    Oct 28 '20 at 19:36
  • Oh, and you can trace-function the function you suspect being running twice, should be easier than learning how to debug (which I never learned myself)
    – JJPandari
    Oct 30 '20 at 3:06
2

You have probably set yas-wrap-around-region to t, this will insert your region at the snippet placeholder $0. Calling yas-new-snippet will expand a snippet to create your new snippet: yas-new-snippet-default. If you look at the default value, it contains $0 and yas-selected-text, and now both will be filled with your region.

I suggested a fix in this PR: https://github.com/joaotavora/yasnippet/pull/1102

As a workaround, you could advice the function like this:

(defun yas-new-snippet-fix-region (func &rest args)
  (let ((yas-wrap-around-region nil))
    (apply func args)))
(advice-add 'yas-new-snippet :around #'yas-new-snippet-fix-region)
1
  • you were right - yas-wrap-around-regions is true indeed. Just followed your pull request. Hopefully it will be merged soon. Thanks May 11 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.