Need help indenting my code

Need help indenting my code

Post by sarah cha » Sun, 13 Jul 2003 04:02:43



Right now my EMACS indents my functions as follows:

int main (int arg1, int arg2)
    {
         return 0;
    }

I would like to change it so that it indents like this:

int main (int arg1, int arg2)
{
     return 0;

Quote:}

Could anyone tell me what to change in my .emacs to make this happen?

Thanks! :)

Sarah

 
 
 

Need help indenting my code

Post by Chris McMaha » Sun, 13 Jul 2003 09:09:57


Certainly!

Look at the function c-set-offset. I believe the one you want is
substatement-open.

I use the following for my JDE hook for editing Java files.

(defun my-jde-mode-hook ()
  (c-set-offset 'substatement-open 0)
  (c-set-offset 'statement-case-open 0)
  (c-set-offset 'case-label '+)
  (c-set-offset 'arglist-intro '+)
  (c-set-offset 'arglist-cont-nonempty '+)
  (setq c-comment-continuation-stars "* "
        c-basic-offset 4)
  )
(add-hook 'jde-mode-hook 'my-jde-mode-hook)

- Chris


> Right now my EMACS indents my functions as follows:

> int main (int arg1, int arg2)
>     {
>          return 0;
>     }

> I would like to change it so that it indents like this:

> int main (int arg1, int arg2)
> {
>      return 0;
> }

> Could anyone tell me what to change in my .emacs to make this happen?

> Thanks! :)

> Sarah

--
     (.   .)
  =ooO=(_)=Ooo========================
  Chris McMahan | cmcmahan-AT-one.net
  ====================================

 
 
 

Need help indenting my code

Post by sarah cha » Sun, 13 Jul 2003 11:08:17


Thanks, Chris!

Right now, my .emacs looks like this:

(c-add-style "default"
   '((c-basic-offset . 4)
     (c-comment-only-line-offset . 0)
     (c-offsets-alist . ((block-open . 0)
                         (substatement-open . 0)
                         (access-label . -2)
                         (case-label . 2)
                         (statement-case-intro . 2)
                         (statement-case-open . 0)
                         (label . 2)
                         ))
    )
)
(defvar c-site-default-style "default")
(setq c-default-style '((java-mode . "default") (c-mode . "default")))

I already have substatement-open = 0, but maybe you can see what else
might be causing the problem?

Thanks again!!!

Sarah
:)

 
 
 

Need help indenting my code

Post by Chris McMaha » Sun, 13 Jul 2003 11:34:11


You can get a good guide to the meanings of the various settings
available by getting help on the variable c-offsets-alist.

Just put your cursor on the variable name
c-offsets-alist
and press C-h v

You can also set the variable

c-echo-syntactic-information-p

to non-`nil' to see the component that is being indented.

Also look at your hook into java-mode and c-mode
It appears that your defined style is not being used.

Use an 'add-hook function to do this:

(add-hook 'jde-mode-hook 'my-jde-mode-hook)

- Chris


> Thanks, Chris!

> Right now, my .emacs looks like this:

> (c-add-style "default"
>    '((c-basic-offset . 4)
>      (c-comment-only-line-offset . 0)
>      (c-offsets-alist . ((block-open . 0)
>                          (substatement-open . 0)
>                          (access-label . -2)
>                          (case-label . 2)
>                          (statement-case-intro . 2)
>                          (statement-case-open . 0)
>                          (label . 2)
>                          ))
>     )
> )
> (defvar c-site-default-style "default")
> (setq c-default-style '((java-mode . "default") (c-mode . "default")))

> I already have substatement-open = 0, but maybe you can see what else
> might be causing the problem?

> Thanks again!!!

> Sarah
> :)

--
     (.   .)
  =ooO=(_)=Ooo========================
  Chris McMahan | cmcmahan-AT-one.net
  ====================================
 
 
 

Need help indenting my code

Post by Eric Friedm » Sun, 13 Jul 2003 12:56:41


Looks like BSD style to me -- why not simply customize CC mode so
that it uses that style?  Be sure to delete any other mods to the
offsets for c-mode.


<Right now my EMACS indents my functions as follows:
<
<int main (int arg1, int arg2)
<    {
<         return 0;
<    }
<
<
<I would like to change it so that it indents like this:
<
<int main (int arg1, int arg2)
<{
<     return 0;
<}
<
<Could anyone tell me what to change in my .emacs to make this happen?
<
<Thanks! :)
<
<Sarah

 
 
 

1. xemacs 19.13 help custom indent c code

I have xemacs 19.13 and I want to custom indent my c code...
I like the brackets to be below (and in the same column) as the
start of a statement and, the body to be indented.  I have been
able to get a 3 space indent but it indents the brackets also.  

I use this to set the indent:
      (add-hook 'c-mode-hook (lambda () (setq c-basic-offset 3)))

Any hints would be appreciated...

Thanks
Mike

2. Win2k Replication Problem

3. Need help with either indent-tabs-mode and tab stop list

4. Problems with USR Sportster? Try This...

5. Help needed in Emacs-Lisp coding.

6. VC vs VB Productivity/Quality

7. Need a NNTP server that talk back + who needs help compiling Uemacs 3.11 for VMS?

8. Daft Web Page of the Week...

9. Need help linking new MicroEMACS/ need termcap.lib ?

10. Help Needed: convert MS-window help file to emacs info file

11. Help needed: Rebinding key in help-map (GNU Emacs)

12. indenting C-Code

13. How to write e-lisp function to auto-indent code