Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs and C++ { } indenting

In the past I've successfully used:

M-x c-set-style

Possible completions are:
bsd				   cc-mode
ellemtel			   gnu
java				   k&r
linux				   python
stroustrup			   user

A friend of mine sent me this, but I haven't tried it.  Perhaps it
contains something that will help you out.

Here's a new Emacs lisp function for guys to set the indentation level
of a buffer when you're programming in one of the C-like languages
(C, C++, Java).  The useful function in here is "set-c-indent", which
will prompt you for the number of spaces to indent code in the current
buffer (when you hit TAB in the C major mode or use C-M-\).  The function
sets the indentation level for the current buffer and leaves other buffers
alone.  After the indentation level is set, a message will be displayed in
the mini-buffer telling you what the level is now set to.  You can tie the
function to a key using the global-set-key function (below, I bind the 
function to C-c i).  The other functions are for setting the indentation 
styles of various SCE personalities, and show how to call the function 

(defun set-c-indent (offset)
  "Sets the c-basic-offset for a buffer interactively"
  (interactive "nEnter new C indent value: ")
  (message "%s%d%s" "Set C indent to " offset " spaces.")
  (make-variable-buffer-local 'c-basic-offset)
  (setq c-basic-offset offset)

(defun set-c-indent-tim () 
  "Sets Tim's C indentation style" (interactive) (set-c-indent 2))
(defun set-c-indent-bob () 
  "Sets Bob's C indentation style" (interactive) (set-c-indent 3))
(defun set-c-indent-ilane ()
  "Sets Ilane's C indentation style" (interactive) (set-c-indent 4))

(global-set-key "\C-ci" 'set-c-indent)
(global-set-key "\C-ct" 'set-c-indent-tim)
(global-set-key "\C-cb" 'set-c-indent-bob)
(global-set-key "\C-cl" 'set-c-indent-ilane)


BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /