CC MODE Version 5 Documentation. Node: Minor Modes

PREV New Indentation Engine UP Top NEXT Commands

Chapter 4: Minor Modes

CC Mode contains two minor-mode-like features that you should find useful while you enter new C code. The first is called auto-newline mode, and the second is called hungry-delete mode. These minor modes can be toggled on and off independently, and CC Mode can be configured so that it starts up with any combination of these minor modes. By default, both of these minor modes are turned off.

The state of the minor modes is always reflected in the minor mode list on the modeline of the CC Mode buffer. When auto-newline mode is enabled, you will see `C/a' on the mode line [1]. When hungry delete mode is enabled you would see `C/h' and when both modes are enabled, you'd see `C/ah'.

CC Mode provides keybindings which allow you to toggle the minor modes on the fly while editing code. To toggle just the auto-newline state, hit C-c C-a (c-toggle-auto-state). When you do this, you should see the `a' indicator either appear or disappear on the modeline. Similarly, to toggle just the hungry-delete state, use C-c C-d (c-toggle-hungry-state), and to toggle both states, use C-c C-t (c-toggle-auto-hungry-state).

To set up the auto-newline and hungry-delete states to your preferred values, you would need to add some lisp to your `.emacs' file that called one of the c-toggle-*-state functions directly. When called programmatically, each function takes a numeric value, where a positive number enables the minor mode, a negative number disables the mode, and zero toggles the current state of the mode.

So for example, if you wanted to enable both auto-newline and hungry-delete for all your C file editing, you could add the following to your `.emacs' file:

(add-hook 'c-mode-common-hook
	  '(lambda () (c-toggle-auto-hungry-state 1)))

  • Auto-newline insertion
  • Hungry-deletion of whitespace
  • Auto-fill mode interaction

  • [1] Remember that the `C' could be replaced with `C++', `ObjC', `Java' or `IDL'.

    PREV New Indentation Engine UP Top NEXT Commands