11

Since several years I've been using this snippet to insert a date into buffer:

# -*- coding: utf-8 -*-
# name: date
# key: date
# --
`(insert (format-time-string "%Y-%m-%d"))`$0

However nowadays I get this annoying warning:

Warning (yasnippet): `date' modified buffer in a backquote expression.
To hide this warning, add (yasnippet backquote-change) to `warning-suppress-types'.

This is clearly related to this question, but it is not clear what is the proper way to fix the snippet (rather then just suppress the message).

user673592
  • 839
  • 7
  • 17

1 Answers1

19

You should rewrite your snippet so that the backquoted expression doesn't modify the buffer, but instead returns the string to insert:

# -*- coding: utf-8 -*-
# name: date
# key: date
# --
`(format-time-string "%Y-%m-%d")`$0

For more examples, see yasnippet truncates clipboard contents

npostavs
  • 9,033
  • 1
  • 21
  • 53