1

Trying to write a yasnippet for a markdown code block I wrote the following:

#name: Code Block
#contributor: Rovanion Luckey <[email protected]>
# --

\`\`\`${1:language}
${2:code}
\`\`\`

Since according to the documentation you have to escape the backquotes. Though when I try to call on the snippet in my markdown document I only get:

YASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARDlanguage
code
YASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARD

Worth mentioning is that neither

```${1:language}
${2:code}
```

works.

7
  • This looks like joaotavora/yasnippet#800, but I was unable to reproduce it, and neither was the OP after restarting Emacs.
    – npostavs
    Commented Apr 27, 2017 at 12:44
  • Hmm, I just restarted emacs and now it's working as intended.
    – Rovanion
    Commented Apr 27, 2017 at 13:07
  • Oh I didn't update yasnippet. I merely restarted emacs. I'm on version 0.11.0 right now.
    – Rovanion
    Commented Apr 27, 2017 at 14:16
  • Had you updated yasnippet there in the session where you got the bad result? And if so, which version did you update from?
    – npostavs
    Commented Apr 27, 2017 at 14:28
  • No, haven't touched my emacs packages for a month perhaps. This machine has definitely been restarted since.
    – Rovanion
    Commented Apr 27, 2017 at 14:54

1 Answer 1

1

The original example given in the question is correct, but due to a bug in yasnippet expanding a snippet which uses incorrect syntax will cause subsequent expansions to fail. For example, if you first tried

```${1:javascript}
$0
```

This fails to expand properly, producing YYYYY (with error Wrong type argument: char-or-string-p, (end-of-file)). That's because the backquotes are not escaped. But even after fixing it to

\`\`\`${1:javascript}
$0
\`\`\`

that still fails to expand properly, producing

YASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARDjavascript

YASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARDYASESCAPE96PROTECTGUARD

(with error Wrong type argument: char-or-string-p, (${1:javascript})). If you keep expanding a few more times, it will eventually work, as the incorrect internal state gets removed.


The bug is fixed as of 2018 Feb 4, in what will be version 0.13. For older versions, it can be worked around by evaluating (setq yas--backquote-markers-and-strings nil).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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