unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Unusual C indentation conventions
@ 2005-03-28 23:21 no spam
  2005-03-29 12:57 ` Greg Rowe
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: no spam @ 2005-03-28 23:21 UTC (permalink / raw)


hi, I've spent a fair amount of time trying to get emacs to do something 
reasonably close to what's required in my installation, and I find that 
it usually doesn't and I can't figure out why.  I'll manually space the 
bracket { to be where I want it, and then as soon as I start typing, 
it'll re-indent it, and even the .emacs variables that I would have 
thought would just turn off ALL syntax-directed indentation don't seem 
to do it.

All complaining aside, though:  what can I put in my .emacs to cause it 
to do this:

===================

The code follows an indentation convention that is a bit
unusual for C.  Opening and closing braces are on
a line by themselves and are indented at the same
level as the block they enclose:
     if (someTest)
         {
         doSomething();
         doSomethingElse();
         }
Tab stops are set to 8.  Each block of code is
indented by 4 from the previous block.  (In the
vi editor set ts=8  set sw=4)

=================

??


Thanks in advance.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unusual C indentation conventions
  2005-03-28 23:21 Unusual C indentation conventions no spam
@ 2005-03-29 12:57 ` Greg Rowe
  2005-03-29 15:48 ` Peter Lee
  2005-03-29 18:23 ` Alan Mackenzie
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Rowe @ 2005-03-29 12:57 UTC (permalink / raw)


no spam wrote:
> The code follows an indentation convention that is a bit
> unusual for C.  Opening and closing braces are on
> a line by themselves and are indented at the same
> level as the block they enclose:
>     if (someTest)
>         {
>         doSomething();
>         doSomethingElse();
>         }
> Tab stops are set to 8.  Each block of code is
> indented by 4 from the previous block.  (In the
> vi editor set ts=8  set sw=4)


The coding style whitesmith is close.  C-c . to run c-set-style.  Choose 
whitesmith.  You can change the indenting amount in cc-mode by doing M-x 
set-variable and set c-basic-offset to the number of spaces you desire.

You can change the tab stop width using the tab-width variable.  M-x 
set-variable again.

In your .emacs you might want something like the following to make 
everything happen automatically:


(add-hook c-mode
	(lambda ()
		(c-set-style "whitesmith")
		(setq c-basic-offset 4)
		(setq tab-width 8)))

Good luck!

Greg

-- 
Home is where the .bashrc is.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unusual C indentation conventions
  2005-03-28 23:21 Unusual C indentation conventions no spam
  2005-03-29 12:57 ` Greg Rowe
@ 2005-03-29 15:48 ` Peter Lee
  2005-03-29 18:23 ` Alan Mackenzie
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Lee @ 2005-03-29 15:48 UTC (permalink / raw)


>>>> no spam writes:

    >      if (someTest)
    >          {
    >          doSomething();
    >          doSomethingElse();
    >          }
    > Tab stops are set to 8.  Each block of code is
    > indented by 4 from the previous block.  (In the
    > vi editor set ts=8  set sw=4)

Try this.. you'll probably want to modify the tabs.


(setq indent-tabs-mode nil
      tab-always-indent nil
      tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60)
      tab-width 4)

(defun my-c-mode-common-hook ()
  (turn-on-font-lock)
  (setq c-tab-always-indent nil)
  (c-set-offset 'substatement-open 0)
  (c-set-offset 'arglist-intro 1)
  (c-set-offset 'defun-open 4)
  (c-set-offset 'defun-block-intro 0)
  (c-set-offset 'statement 0)
  (c-set-offset 'substatement-open 4)
  (c-set-offset 'statement-block-intro 0)
  (c-set-offset 'substatement 4)
  (c-set-offset 'statement-cont 4)
  (c-set-offset 'label -4)
  (c-set-offset 'topmost-intro-cont 4)
  (c-set-offset 'brace-list-intro 0)
  (c-set-offset 'class-open 4)
  (c-set-offset 'class-close 4)
  (c-set-offset 'topmost-intro '-)
  (c-set-offset 'brace-list-open 4)
  (c-set-offset 'access-label '--)
  (c-set-offset 'func-decl-cont 0)
  (c-set-offset 'case-label 0)
  (c-set-offset 'statement-case-intro 4)
  (c-set-offset 'statement-case-open 4)
  (c-set-offset 'inline-open '+))

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unusual C indentation conventions
  2005-03-28 23:21 Unusual C indentation conventions no spam
  2005-03-29 12:57 ` Greg Rowe
  2005-03-29 15:48 ` Peter Lee
@ 2005-03-29 18:23 ` Alan Mackenzie
  2 siblings, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2005-03-29 18:23 UTC (permalink / raw)


no spam <peoria6384@yahoo.com> wrote on Mon, 28 Mar 2005 23:21:12 GMT:
> hi, I've spent a fair amount of time trying to get emacs to do
> something reasonably close to what's required in my installation, and I
> find that it usually doesn't and I can't figure out why.  I'll manually
> space the bracket { to be where I want it, and then as soon as I start
> typing, it'll re-indent it, .....

This is a recognized problem, and the next version of CC Mode (5.31) will
enable users to disable "electric indentation", though the precise
details of this haven't quite been finalized.

> .... and even the .emacs variables that I would have thought would just
> turn off ALL syntax-directed indentation don't seem to do it.

(setq c-syntactic-indentation nil) should do it.  Have you tried that?

> All complaining aside, though:  ....

Please do complain!  If nobody complained about the things which annoy
them, nothing would get fixed.  ;-)

[ .... ]

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-29 18:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-28 23:21 Unusual C indentation conventions no spam
2005-03-29 12:57 ` Greg Rowe
2005-03-29 15:48 ` Peter Lee
2005-03-29 18:23 ` Alan Mackenzie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).