I created a yasnippet that calls a function:
# -*- mode: snippet -*-
# name: print
# key: pr
# --
`(cperl-print)`
The function code:
(defun cperl-print ()
(interactive)
(let* ((current (point))
(end (line-end-position)))
(if (< current end)
(insert "print")
(progn
(insert "print ;")
(backward-char 1))
)))
Unfortunately, backward-char
doesn't produce any effect when called from inside yasnippet. When the function is called directly, it works. Is there any way to fix this?
insert
within backquotes... Per the snippet writing tutorial joaotavora.github.io/yasnippet/snippet-development.html : "Note: backquote expressions should not modify the buffer. Please note that the lisp forms in backquotes should not modify the buffer, doing so will trigger a warning. For example, instead of doing ..."yasnippet
, it was possible to return a string with a place holder of where to end such as"print$0;"
and that would have solved your problem -- along with there being no need to use(insert "....")
, i.e., just return the string itself. However, that previous solution no longer works because there is an args out of range error. If @npostavs is still active on this forum, then he may have a solution for you. If a satisfactory answer is not forthcoming in a reasonable period of time, then you may wish to consider submitting an Issue on Github to obtain some guidance.