Edit Opensolaris Source with Emacs

From Genunix

Jump to: navigation, search

This article is supposed to provide configuration and usage information for OpenSolaris source editing with GNU emacs and xemacs.

Sun C-Style mode for Emacs

To get proper indentation and line continuation with emacs according to the original Sun style guide and the developer reference style guide, cc-mode needs to be customized. The recommendations here are to be considered work in progress (please add your contributions/corrections) and are based upon work of Binu Jose Philip posted in this blog entry. Jmcp has posted an alternative implementation in his blog.

Setup:

emacs -batch -no-site-file -q -f batch-byte-compile cc-*.el
  • Copy cstyle.el to your .xemacs directory (or anywhere else)
  • Add the following to your .emacs or .xemacs/init.el
(load-library "cc-mode.elc")
(load-library "cc-fonts.elc")
(load-file "/path/to/your/cstyle.el")  ;; change path to where you put cstyle.el
(indent-according-to-mode)
(setq c-auto-newline t)
(autoload 'c-mode "c-mode.elc")

You should now get OpenSolaris style guide conforming indentation and line continuation with emacs.

Please help by adding corrections and improvements!

Customizations

Add these customizations to your .emacs or .xemacs/init.el file:

  • By default, emacs will always indent a code line when TAB is pressed. To get indentation only if TAB is pressed at the beginning of a line, use
(setq c-tab-always-indent nil)

See also

Mercurial Editor modes

Personal tools