0

I know how to create basic snippets using YASnippet.

For example, consider the following snippet:

# -*- mode: snippet -*-
# name: js-function
# key: jsfunc
# --
/** @function
 * @name ${1:fn-name}
 * @description ${2:description}
 * @param  {${3:type}} ${4:name} ${5:desc}
 * @returns {${6:type}} ${7:desc}
 */

const $1 = exports.$1 = ($4) => {
      
};

This works very well, as intended.

I would like to do the following two more things:

  • Keep the number of @params dynamic, and have YASnippet use the tab-stop fields 'type', 'name' and 'description' for each, and then mirroring the 'name'(s) in a comma separated list (using mirrored field transformations perhaps?). I know YASnippet supports embedded elisp, but since I am a noob, I can't really figure out if there is some obvious way to do this using elisp.

  • Automatically insert a '* ' for every line automatically if I insert a multi-line ${2:description} This could in theory be implemented easily if the above functionality is possible. I am currently doing this by M+q`, however it would be nice if this can be done using YASnippet

Following expanded code is what I would like to achieve dynamically:

/** @function
 * @name generateDSAKey
 * @description Generate a DSA Keypair
 * @param  {int} keysize keysize of the DSA
 * @param {function} cb callback function 
 * @returns {undefined}
 */

const generateDSAKey = exports.generateDSAKey = (keysize, cb) => {
    
};

Any help in this regard is much appreciated

2
  • Elisp tag is only for questions about elisp as lenguage itself.
    – Muihlinn
    Dec 11 '20 at 17:29
  • Ah, I see. My bad. First time posting here. Dec 14 '20 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.