Sometimes it would be handy to get the previously entered field values, and process them.

Example: the second field (function name) of this snippet is always the camelCase version of the first field (description) in my workflow.

describe('$1', function $2() {

To write lisp function to do this, one should know how to get the value of the first field.


1 Answer 1


According to the Yasnippet Documentation in the Mirrors with Transformations, you can have a $1 substitution multiple times in your snippet, but each one can be transformed. Try this:

describe('$1', function ${1:$(camelize yas-text)}() {

That said, you'll need a camelize function written in Lisp. Check out the examples on the Emacs Wiki, like:

(defun camelize (s)
  "Convert under_score string S to CamelCase string."
  (mapconcat 'identity (mapcar
                        '(lambda (word) (capitalize (downcase word)))
                        (split-string s "_")) ""))

Hope that helps.

  • Don't quote the (lambda ...) form
    – npostavs
    Commented Oct 3, 2016 at 18:38
  • Thanks, it worked nice. I modified it a bit to my specific case. (defun my/camelize (s) "Convert under_score string S to CamelCase string." (store-substring (mapconcat 'identity (mapcar (lambda (word) (capitalize (downcase word))) (split-string s "[-_ ]+")) "") 0 (if (> (length s) 0) (downcase (substring s 0 1)))))
    – atevm
    Commented Oct 4, 2016 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.