2

I am trying to write a snippet to generate different python based on which directory I am in, as in some directories, I am using an older version of python. The snippet is

# key: log
# name: logger
# --
`(if (string-match "/projects/old" default-directory )
     "logger.info('$1: {}'.format($1))"
   "logger.info(f'$1: {$1}')" )
`

This sort of works. It correctly figures out the new/old problem, but yasnippet is not paying attention to the placeholders. An older version using just

     "logger.info('$1: {}'.format($1))"

processed the placeholders as expected, but obviously did not generate both forms. What do I do to enable placeholders inside the return value of a lisp expression?

0
0

This was answered on the gitlab site. Duplicating it here in case someone finds this page first.

Yes, yasnippet doesn't support interpreting expanded strings in snippet syntax. I suggest making a # type: command instead:

# key: log
# name: logger
# type: command
# --
(yas-expand-snippet
  (if (string-match "/projects/old" default-directory )
       "logger.info('$1: {}'.format($1))"
     "logger.info(f'$1: {$1}')"))

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.