Search code examples
emacsyasnippetcperl-mode

Emacs: how to get rid of the unwanted tab in perl-mode yasnippet


I have the following yasnippet in perl-mode to create a sub:

#name : sub ... { ... }
#key: sub
# --
sub ${1:function_name}
# {{{
{
    $0
}
# }}}

But when Emacs expands it, it generates an unwanted tab:

sub function_name
    # {{{ <-- ?
{

}
# }}}

I don't don't have this tab in the snippet definition, so it seems, that it is added by cperl-mode (perl-mode yasnippets are activated in cperl-mode). How to get rid of it?


Solution

  • When you insert a snippet, indentation is performed automatically. Add a line to your snippet to prevent this behavior as follows:

    #name : sub ... { ... }
    #key: sub
    #expand-env: ((yas-indent-line 'fixed))
    # --
    sub ${1:function_name}
    # {{{
    {
        $0
    }
    # }}}