Just recently started using yasnippet for emacs and really like the way it works, however I've run into a minor nuisance I'd like some help to solve if possible.
One snippet I like in particular is the "for"-snippet, i.e.:
# -*- mode: snippet -*-
# name: for
# key: for
# --
for (${1:i = 0}; ${2:i < N}; ${3:i++}) {
$0
}
However I recently started working on a project where we have a different coding style. Simply put the snippet above would be changed to place the starting brace position to:
# -*- mode: snippet -*-
# name: for
# key: for
# --
for (${1:i = 0}; ${2:i < N}; ${3:i++})
{
$0
}
I would however like to easily switch between different projects and consequently between different coding styles without having to manually change the snippets or create many duplicates. So I figured it should be possible to write some elisp code in the snippet to automatically adapt to the currently active coding style.
Looking around at some of the Emacs/elisp documentation, I found the so called c-hanging-brace-alist (GNU doc) which I feel I should be able to use somehow. However I have never really done any programming in elisp, and I'm not really sure how to accomplish this. Any help or advice would be appreciated!