0
votes

After over two weeks emacs 24.3 for Mountain Lion 10.8.3 setup, I am still unable to fix the indentation setup.

The issues: - in scratch mode & R mode the indentation is not working. I am now using spaces - in C++ mode, I have to toggle off the syntactic indentation in order to indent for a width of 2 columns. I want to do at least 3 columns but failed with the .emacs file

 ;; Set default tab to 4 spaces   
(setq default-tab-width 4)

Emacswiki said the TAB indentation is only temporarily activated for auto-complete prompt so I set this up in .emacs file as well

(ac-set-trigger-key "TAB")

Because I cannot use TAB to indent, I just disable the settings above and still unsuccessful.

There is very lengthy materials in CC mode about indentation. However, I am happy with C++ mode and auto-complete. And I am hesitant to waste a few more days on CC mode just for sake of indentation.

Is there global settings for indentation in .emacs file? If no such settings, what should be the correct settings for indentation for C++ and ESS model (R) in .emacs file?

1
tab-width has nothing to do with indentation, it only controls the display-width of a TAB character. You want to change things like foo-indent-offset or foo-basic-indent. - Stefan

1 Answers

1
votes

You seem to think that using CC mode would mean not using C++ mode. Actually cc-mode is the package that provides C++ mode. So the info you saw about how to set up indentation for CC mode should apply to C++ mode.

Here is a simplification of what I have in my .emacs:

(defun set-up-c-mode-styles ()  
 (c-add-style
   "mystyle"
   '(
     (c-basic-offset             . 3)
     (c-hanging-braces-alist     . nil )
     (c-block-comments-indent-p  . nil )
     (c-recognize-knr-p          . t)
     (c-offsets-alist . (
             (substatement         . +)
             (substatement-open    . 0)
             (case-label           . 0)
             (statement-case-intro . +)
             (statement-case-open  . +)
             (arglist-close        . 0)
             (defun-close          . 0)
             )
              )
     )
   't
   )
  (c-set-style "mystyle")
  )
(add-hook 'c-mode-common-hook 'set-up-c-mode-styles)