The meaning of backquotes in a snippet is to insert the value of the form within the backquotes into the snippet expansion. However, indent-region
works by side-effect, and in recent Emacs versions happens to return t
. As politza suggested in the comments, you can use (progn (indent-region ...) nil)
to drop the return value.
However, this still performs a side effect inside backquotes which will stop being supported in some future version (it triggers a warning in versions 0.11 and higher). In this case, the indentation effect can be written much clearer by binding yas-also-auto-indent-first-line
:
# -*- mode: snippet -*-
# name : case : {...}
# key: case
# expand-env: ((yas-also-auto-indent-first-line t))
# --
case ${2:constexpr}:${3: \{}
$0
break;
${3:$(if (string-match "\{" yas-text) "\}" "")}
This modification has just been accepted at https://github.com/AndreaCrotti/yasnippet-snippets/pull/176, and will come with the next yasnippet version (0.12), at least for MELPA packages which integrate snippets from that repo. For other examples of avoiding side effects within backquotes, see yasnippet truncates clipboard contents.
(progn (indent-region ...) nil)
.indent-region
is(setq deactivate-mark t)
, andsetq
does return its value. This is a (relatively) recent change to the function.# expand-env: ((yas-also-auto-indent-first-line t))
to your snippet instead of trying to indent by side-effect like that.