Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

try catch block indentation in Emacs

I'm using the bsd style of indentation in emacs & I'd like to modify it a bit. The related portion of my .emacs file is below. When I write a function with try catch blocks the braces are indented. I'd like them to not indent similar to a function.

What's it's doing now.

try 
    {
    }
catch 
    {
    }

What I'd like it to do.

try 
{
}
catch 
{
}

.emacs file

(defun my-c-mode-common-hook ()
  ;; my customizations for all of c-mode and related modes
  ;; other customizations can go here
  (setq c-default-style "bsd")
  (setq c-basic-offset 4)
  (setq indent-tabs-mode nil)
  )

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

Any help would be appreciated.

like image 874
Stephen Burke Avatar asked Jan 24 '09 17:01

Stephen Burke


People also ask

How to indent program?

Should You Use Tab or Space to Indent? Technically, it is fine to either indent using the tab key or with the space bar. Indenting once with the tab key means just pressing the tab key once. Indenting once with the space bar means pressing the space bar 4 times.

Does indentation matter in c?

Both C and C++ are not affected by white space in their interpretation of the code. That does not mean the programmer should not care about its misuse.


1 Answers

Go to the line with the indent you'd like to change and press C-c C-o. This runs c-set-offset and defaults to the current line's syntax (in this case substatement-open). '+' means one level of indent, '-' means one level unindent, and '0' means no additional indent. You want 0. To make it permanent, add (c-set-offset 'substatement-open 0) to your hook.

like image 160
scottfrazer Avatar answered Sep 28 '22 01:09

scottfrazer