You are not logged in.

#1 2008-10-31 01:27:54

Kruppe
Member
Registered: 2008-09-28
Posts: 30

[solved] emacs, trouble with indentation in C++ mode

I'm obviously missing something in the configurations, i want to get emacs auto indentation and electric keys working. Right now i have the tab length the way i want, and the electric keys "{" and "}" work fine for the main function and other functions, but as soon as i use an if statement or for loop an extra tab is added before the opening and closing braces.

Im using C++ mode and the three minor modes: syntactical indentation, electric mode, and auto newline.

here is a code snippet showing what I'm refering to:

#include <iostream.h>

int main()
{
    if(true)
        {
        }
    
}

here is my .emacs file:

;;support for Lua
(setq auto-mode-alist (cons '("\.lua$" . lua-mode) auto-mode-alist))
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)

;;keybindings
(windmove-default-keybindings 'meta)

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(c-basic-offset 4)
 '(c-insert-tab-function (quote tab-to-tab-stop))
 '(show-paren-mode t)
 '(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60)))
 '(tab-width 4)
 '(x-select-enable-clipboard t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

anyone know what option i have to fiddle with?

Last edited by Kruppe (2008-10-31 03:03:09)

Offline

#2 2008-10-31 02:28:19

Kruppe
Member
Registered: 2008-09-28
Posts: 30

Re: [solved] emacs, trouble with indentation in C++ mode

For the curious, the solution was to edit the c-offsets-alist.

The following line needed adding to the .emacs file:

 '(c-offsets-alist (quote ((substatement . 0) (substatement-open . 0) (substatement-label . 0))))

Offline

Board footer

Powered by FluxBB