[vtk-developers] Emacs VTK code indentation

Ken Martin ken.martin at kitware.com
Thu Feb 3 15:41:36 EST 2005

I'm not sure if this has been posted before and there are probably better
versions out there, but... if you are looking for the emacs settings to get
emacs to indent code according to VTK style, here is a snippit of my .emacs
file that I use...

;----------------- c++ mode stuff --------------------
(autoload 'cc-mode "cc-mode"
	  "Load cc-mode.el to set up a mode for Gnu++"

 (require 'cc-mode)
(set-default 'c-auto-newline t)
(set-default 'c-hungry-delete-key t)
(defun auto-indent-hack ()
(define-key c++-mode-map "\r" 'auto-indent-hack)

;; filess with .C extension should invoke C++ mode
(setq auto-mode-alist (append '(("\\.c$" . c++-mode)
				("\\.cc$" . c++-mode)
				("\\.cs$" . c++-mode)
				("\\.cxx$" . c++-mode)
				("\\.make$" . makefile-mode)
				("\\.h$" . c++-mode)
				("\\.hh$" . c++-mode)
				("\\.H$" . c++-mode)
				("\\.C$" . c++-mode)
				("\\.cmake$" . cmake-mode)
				("CMakeLists.txt" . cmake-mode)
				("GNUmakefile" . makefile-mode)
				("Makefile" . makefile-mode))

(setq c-basic-offset 2)
(setq c-default-style "user") 

(defun kens-c-statement-block-intro (langelem)
  ;; indent by c-basic-offset only if in column 1
    (if (= 
	   (re-search-backward "{" 1) (current-column)) 0)
      ;; otherwise dont indent
(c-set-offset 'statement-block-intro 'kens-c-statement-block-intro)

;--------------end c++ mode stuff---------------------------

(set-default 'indent-tabs-mode nil)

More information about the vtk-developers mailing list