Search code examples
c++emacselispemacs24yasnippet

How to configure Emacs 24 to K&R(or Stroutrup) style?


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)


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.