Question

I want the code like this.

for (;;) {

}

But YASnippet always output this.

for (;;)
{

}

Is there a way to change the C++ style?

This is my .emacs file.

(setq c-default-style "stroustrup")

(add-to-list 'load-path "~/emacs/yasnippet/") (require 'yasnippet) (yas-global-mode 1)

Was it helpful?

Solution

You'd just have to edit the snippet for yourself. It's located in snippets/cc-mode/for. Here's how mine looks like:

# -*- mode: snippet -*-
#name : for (...; ...; ...) { ... }
# --
for (unsigned int ${1:i}=0; $1<${2:N}; ++$1)$0

I insert the braces separately with a function from here, since sometimes you need braces and sometimes not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top