Skip to main content
edited title
Link

C Mode Indentation Problem Why does hook to set up C++ mode indentation not work?

Source Link
Husain
  • 495
  • 8
  • 12

C Mode Indentation Problem

This is my code

(defun my/set-c-mode ()
 (local-set-key (kbd "C-c C-c") 'compile)
 (setq compilation-finish-function 'compilation-exit-autoclose-clone)
 (setq c-default-style "linux")
 (setq c-indent-level 8)
 (setq c-brace-imaginary-offset 0)
 (setq c-brace-offset -8)
 (setq c-argdecl-indent 8)
 (setq c-label-offset -8)
 (setq c-continued-statement-offset 8))
(add-hook 'c++-mode-hook      'my/set-c-mode)

Yet it does not indent correctly. This should give me the linux style indentation, but what I get is this:

/* File: ast.cc
 *

 ------------
 */

#include "ast.h"
#include "ast_type.h"
#include "ast_decl.h"
#include <string.h> // strdup
#include <stdio.h>  // printf

Node::Node(yyltype loc) {
  location = new yyltype(loc);
  parent = NULL;
}

Node::Node() {
  location = NULL;
  parent = NULL;
}
     
Identifier::Identifier(yyltype loc, const char *n) : Node(loc) {
  name = strdup(n);
} 

Any Idea why?