all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* C formatting
@ 2002-12-28  0:17 Oodini
  2002-12-28  0:39 ` Bijan Soleymani
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Oodini @ 2002-12-28  0:17 UTC (permalink / raw)


hello,

I am fighting with EMacs in order to get my programmation style:

void function(int x, int y)
{
      blabla;
      if (...)
      {
           blabla
           blabla
      }
      else
           blabla;
}

I ma desesperatly playing in my .emacs with the following statements, 
but no luck:

(setq c-mode-hook
     (function
       (lambda ()
        (setq c-basic-offset 0)
        (setq c-indent-level 5)
        (setq c-continued-statement-offset 5)
        (setq c-argdecl-indent 0)
        (setq c-brace-offset -5)
        (setq c-label-offset -5)
       )
     )
)

If someone has the same formatiing habits, please give me your setup 
values...

By the way, there is no way, in the buffer, to put two following tabs ??

Thanks for help !

-- 
  .      .
  .  .:::.          ###           \|/        `  ___  '
    :(o o):  .     (o o)         (o o)      -  (O o)  -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

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

* Re: C formatting
  2002-12-28  0:17 C formatting Oodini
@ 2002-12-28  0:39 ` Bijan Soleymani
  2002-12-28 11:47   ` Oodini
  2002-12-28  1:11 ` chris.danx
  2002-12-28 11:05 ` Kai Großjohann
  2 siblings, 1 reply; 16+ messages in thread
From: Bijan Soleymani @ 2002-12-28  0:39 UTC (permalink / raw)


Oodini <svdbg@free.fr> writes:

> hello,
> 
> I am fighting with EMacs in order to get my programmation style:
No need to fight, this is well documented in the CC-mode manual in the
section about customizing indentation. There is also useful
information in the emacs manual under the section about indentation,
and the section about editing programs.

I think there was a change at some point and if you want to use your
own style you have to set the CC-mode style to user.
 
> By the way, there is no way, in the buffer, to put two following tabs ??
Tab runs the indentation function and indents the current line based
on the current style. If you want to add an extra "tab" you should do
M-i (this is documented in the indentation section of the emacs manual).

Hope that helps,

Bijan

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

* Re: C formatting
  2002-12-28  0:17 C formatting Oodini
  2002-12-28  0:39 ` Bijan Soleymani
@ 2002-12-28  1:11 ` chris.danx
  2002-12-28 12:31   ` Oodini
  2002-12-28 11:05 ` Kai Großjohann
  2 siblings, 1 reply; 16+ messages in thread
From: chris.danx @ 2002-12-28  1:11 UTC (permalink / raw)


Oodini wrote:
> hello,
> 
> I am fighting with EMacs in order to get my programmation style:

Did that a while back too, but thankfully someone gave me some code that 
gives a nice looking indentation style.

> void function(int x, int y)
> {
>      blabla;
>      if (...)
>      {
>           blabla
>           blabla
>      }
>      else
>           blabla;
> }

This works ok for me and produces indentation like above

(add-hook 'c-mode-hook (function (lambda () (c-set-style "bsd") (setq 
c-basic-offset 4))))

and this works for Java mode (just in case you need it later)

(add-hook 'java-mode-hook (function (lambda () (c-set-style "bsd") (setq 
c-basic-offset 4))))


Danx
-- 
for personal replies change spamoff to chris

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

* Re: C formatting
  2002-12-28  0:17 C formatting Oodini
  2002-12-28  0:39 ` Bijan Soleymani
  2002-12-28  1:11 ` chris.danx
@ 2002-12-28 11:05 ` Kai Großjohann
  2002-12-28 12:52   ` Oodini
  2 siblings, 1 reply; 16+ messages in thread
From: Kai Großjohann @ 2002-12-28 11:05 UTC (permalink / raw)


Oodini <svdbg@free.fr> writes:

> I ma desesperatly playing in my .emacs with the following statements,
> but no luck:

I suggest to try C-c C-o on the first line that has wrong indentation
and to follow the prompts.  Then hit TAB to reindent the line.  When
you like the indentation, you can use C-x ESC ESC and then M-p/M-n to
retrieve the right c-set-offset statement.  That's what you can put
in the hook, below:

> (setq c-mode-hook
>      (function
>        (lambda ()
>         (setq c-basic-offset 0)
>         (setq c-indent-level 5)
>         (setq c-continued-statement-offset 5)
>         (setq c-argdecl-indent 0)
>         (setq c-brace-offset -5)
>         (setq c-label-offset -5)
>        )
>      )
> )

This is not a good idea to do, either, as you are overriding old
values for the hook.  Never use setq on a hook.  Always use add-hook
instead.  Here's my suggestion, fill in the missing c-set-offset
statements here:

(defun oodini-c-indent-setup ()
  (setq c-basic-offset 5)
  (c-set-offset ...))
(add-hook 'c-mode-hook 'oodini-c-indent-setup)

You didn't say which version of Emacs you are using.  I'm assuming
Emacs 21.  Probably the above works for Emacs 20, too.
-- 
Ambibibentists unite!

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

* Re: C formatting
  2002-12-28  0:39 ` Bijan Soleymani
@ 2002-12-28 11:47   ` Oodini
  2002-12-28 11:50     ` Oodini
  2002-12-28 13:05     ` Kai Großjohann
  0 siblings, 2 replies; 16+ messages in thread
From: Oodini @ 2002-12-28 11:47 UTC (permalink / raw)


Bijan Soleymani a écrit:


>>I am fighting with EMacs in order to get my programmation style:
> 
> No need to fight, this is well documented in the CC-mode manual in the
> section about customizing indentation. There is also useful
> information in the emacs manual under the section about indentation,
> and the section about editing programs.

I have already read the doc 
(http://www.sunsite.ualberta.ca/Documentation/Gnu/emacs-18.59/html_node/emacs_150.html),
before to post and it didn't help me a lot.
It seems I don't understand it as I should.

-- 
  .      .
  .  .:::.          ###           \|/        `  ___  '
    :(o o):  .     (o o)         (o o)      -  (O o)  -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

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

* Re: C formatting
  2002-12-28 11:47   ` Oodini
@ 2002-12-28 11:50     ` Oodini
  2002-12-28 12:32       ` Jesper Harder
  2002-12-28 13:05     ` Kai Großjohann
  1 sibling, 1 reply; 16+ messages in thread
From: Oodini @ 2002-12-28 11:50 UTC (permalink / raw)


Oodini a écrit:
> Bijan Soleymani a écrit:
> 
> 
>>> I am fighting with EMacs in order to get my programmation style:
>>
>>
>> No need to fight, this is well documented in the CC-mode manual in the
>> section about customizing indentation. There is also useful
>> information in the emacs manual under the section about indentation,
>> and the section about editing programs.
> 
> 
> I have already read the doc 
> (http://www.sunsite.ualberta.ca/Documentation/Gnu/emacs-18.59/html_node/emacs_150.html), 
> 
> before to post and it didn't help me a lot.
> It seems I don't understand it as I should.
> 

Well, it is an old doc. I have found this link with Google, but is about 
release 18.59 (seen in the URL) .... And I am using 21.2.1

-- 
  .      .
  .  .:::.          ###           \|/        `  ___  '
    :(o o):  .     (o o)         (o o)      -  (O o)  -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

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

* Re: C formatting
  2002-12-28  1:11 ` chris.danx
@ 2002-12-28 12:31   ` Oodini
  2002-12-28 12:57     ` chris.danx
  2002-12-28 13:03     ` Kai Großjohann
  0 siblings, 2 replies; 16+ messages in thread
From: Oodini @ 2002-12-28 12:31 UTC (permalink / raw)


chris.danx a écrit:
> Oodini wrote:
> 
>> void function(int x, int y)
>> {
>>      blabla;
>>      if (...)
>>      {
>>           blabla
>>           blabla
>>      }
>>      else
>>           blabla;
>> }
> 
> 
> This works ok for me and produces indentation like above
> 
> (add-hook 'c-mode-hook (function (lambda () (c-set-style "bsd") (setq 
> c-basic-offset 4))))

Well, it doesn't do exactly what I want.
After the "if", when I press Enter, Emacs put an extra indent, whereas I 
want it to put the cursor under the "if". I guess it supposes I put the 
opening brace af the end of the line where there is the "if".

-- 
  .      .
  .  .:::.          ###           \|/        `  ___  '
    :(o o):  .     (o o)         (o o)      -  (O o)  -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

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

* Re: C formatting
  2002-12-28 11:50     ` Oodini
@ 2002-12-28 12:32       ` Jesper Harder
  0 siblings, 0 replies; 16+ messages in thread
From: Jesper Harder @ 2002-12-28 12:32 UTC (permalink / raw)


Oodini <svdbg@free.fr> writes:

> Oodini a écrit:
>
>> I have already read the doc
>> (http://www.sunsite.ualberta.ca/Documentation/Gnu/emacs-18.59/html_node/emacs_150.html),
>> before to post and it didn't help me a lot.  It seems I don't
>> understand it as I should.
>
> Well, it is an old doc. I have found this link with Google, but is
> about release 18.59 (seen in the URL) .... And I am using 21.2.1

Yes, it is obsolete for Emacs 21.  Use the documentation that comes
with Emacs instead -- do

     `C-h i m cc mode'

in Emacs to display the current documentation.  If you're not familiar
with the Emacs documentation system you might want to take the Info
tutorial first:

     `C-h i h'

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

* Re: C formatting
  2002-12-28 11:05 ` Kai Großjohann
@ 2002-12-28 12:52   ` Oodini
  2002-12-28 13:50     ` Kai Großjohann
  2002-12-28 13:53     ` Kai Großjohann
  0 siblings, 2 replies; 16+ messages in thread
From: Oodini @ 2002-12-28 12:52 UTC (permalink / raw)


Kai Großjohann a écrit:


> I suggest to try C-c C-o on the first line that has wrong indentation
> and to follow the prompts.  Then hit TAB to reindent the line.  When
> you like the indentation, you can use C-x ESC ESC and then M-p/M-n to
> retrieve the right c-set-offset statement.  That's what you can put
> in the hook, below:

I started from what an user answer here gave me:

(add-hook 'c-mode-hook
	(function (lambda ()
		(c-set-style "bsd")
		(setq c-basic-offset 4)
	))
)

and then what what you said:
     C-x C-o
I get the the statement
     Syntactic symabol to change: substatement
I hit Enter...
     substatement offset (default +):
I put 0, and then I get the *wanted behaviour*.
     C-x ESC ESC
     redo (c-set-offset (quote substatement) 0 nil)

So I modify my .emacs:

(add-hook 'c-mode-hook
	(function (lambda ()
		(c-set-style "bsd")
		(setq c-basic-offset 4)
		(c-set-offset 0)
	))
)

But then I obtain a different behaviour.
Typically, after an "if", when I go on a new line to do my opening 
brace, and hit Tab, the offset is 12 characters (8 char tab, and four 
characters).

> You didn't say which version of Emacs you are using.  I'm assuming
> Emacs 21.  Probably the above works for Emacs 20, too.

21.2.1

-- 
  .      .
  .  .:::.          ###           \|/        `  ___  '
    :(o o):  .     (o o)         (o o)      -  (O o)  -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

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

* Re: C formatting
  2002-12-28 12:31   ` Oodini
@ 2002-12-28 12:57     ` chris.danx
  2002-12-28 13:03       ` Oodini
  2002-12-28 13:03     ` Kai Großjohann
  1 sibling, 1 reply; 16+ messages in thread
From: chris.danx @ 2002-12-28 12:57 UTC (permalink / raw)


Oodini wrote:

> Well, it doesn't do exactly what I want.
> After the "if", when I press Enter, Emacs put an extra indent, whereas I 
> want it to put the cursor under the "if". I guess it supposes I put the 
> opening brace af the end of the line where there is the "if".

But if you type "{" then it jumps under the if like you want.  There's 
probably a way to make it position the cursor but automatically I don't 
know what it is, sorry.


Danx
-- 
for personal replies change spamoff to chris

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

* Re: C formatting
  2002-12-28 12:57     ` chris.danx
@ 2002-12-28 13:03       ` Oodini
  0 siblings, 0 replies; 16+ messages in thread
From: Oodini @ 2002-12-28 13:03 UTC (permalink / raw)


chris.danx a écrit:
> Oodini wrote:
> 
>> Well, it doesn't do exactly what I want.
>> After the "if", when I press Enter, Emacs put an extra indent, whereas 
>> I want it to put the cursor under the "if". I guess it supposes I put 
>> the opening brace af the end of the line where there is the "if".
> 
> 
> But if you type "{" then it jumps under the if like you want.

Yes, but I want to put the brace _under_ the "if". :-)
Thanks anyway.

-- 
  .      .
  .  .:::.          ###           \|/        `  ___  '
    :(o o):  .     (o o)         (o o)      -  (O o)  -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

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

* Re: C formatting
  2002-12-28 12:31   ` Oodini
  2002-12-28 12:57     ` chris.danx
@ 2002-12-28 13:03     ` Kai Großjohann
  1 sibling, 0 replies; 16+ messages in thread
From: Kai Großjohann @ 2002-12-28 13:03 UTC (permalink / raw)


Oodini <svdbg@free.fr> writes:

> Well, it doesn't do exactly what I want.
> After the "if", when I press Enter, Emacs put an extra indent, whereas
> I want it to put the cursor under the "if". I guess it supposes I put
> the opening brace af the end of the line where there is the "if".

Did you try typing the open brace?  It might move to the left.

If it doesn't, you can still try TAB after typing the open brace.

I guess if there is no brace after if, you do want the next line to
be indented.  So you want:

    if (some_condition)
        some_action;

instead of

    if (some_condition)
    some_action;

Right?  Obviously, Emacs can't know whether you will be typing a
brace or not, after you hit RET.

-- 
Ambibibentists unite!

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

* Re: C formatting
  2002-12-28 11:47   ` Oodini
  2002-12-28 11:50     ` Oodini
@ 2002-12-28 13:05     ` Kai Großjohann
  2002-12-28 13:13       ` Oodini
  1 sibling, 1 reply; 16+ messages in thread
From: Kai Großjohann @ 2002-12-28 13:05 UTC (permalink / raw)


Oodini <svdbg@free.fr> writes:

> I have already read the doc
> (http://www.sunsite.ualberta.ca/Documentation/Gnu/emacs-18.59/html_node/emacs_150.html),
> before to post and it didn't help me a lot.

Oh, boy, that doc is even older than the book!  I think 18.59 was
current in 1993 or so.

*Please* read the documentation that comes with Emacs!

What you're doing is like trying to apply Windows 3.1 documentation
to Windows XP.  (I think the timeframe is about right.  Is it?)
-- 
Ambibibentists unite!

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

* Re: C formatting
  2002-12-28 13:05     ` Kai Großjohann
@ 2002-12-28 13:13       ` Oodini
  0 siblings, 0 replies; 16+ messages in thread
From: Oodini @ 2002-12-28 13:13 UTC (permalink / raw)


Kai Großjohann a écrit:
> Oodini <svdbg@free.fr> writes:
> 
> 
>>I have already read the doc
>>(http://www.sunsite.ualberta.ca/Documentation/Gnu/emacs-18.59/html_node/emacs_150.html),
>>before to post and it didn't help me a lot.
> 
> Oh, boy, that doc is even older than the book!  I think 18.59 was
> current in 1993 or so.

Haha !

> *Please* read the documentation that comes with Emacs!

I do, I do...
I read even the most recent one, now.

> What you're doing is like trying to apply Windows 3.1 documentation
> to Windows XP.  (I think the timeframe is about right.  Is it?)

Why not ??
Emacs proposes us an editor in text mode, even in 2002 :  :->
Some dust has come to my nose, and then thought that a '93 doc would 
have been OK. ;-)

-- 
  .      .
  .  .:::.          ###           \|/        `  ___  '
    :(o o):  .     (o o)         (o o)      -  (O o)  -
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-

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

* Re: C formatting
  2002-12-28 12:52   ` Oodini
@ 2002-12-28 13:50     ` Kai Großjohann
  2002-12-28 13:53     ` Kai Großjohann
  1 sibling, 0 replies; 16+ messages in thread
From: Kai Großjohann @ 2002-12-28 13:50 UTC (permalink / raw)


Oodini <svdbg@free.fr> writes:

> I put 0, and then I get the *wanted behaviour*.
>      C-x ESC ESC
>      redo (c-set-offset (quote substatement) 0 nil)

Well, if you say so.

> So I modify my .emacs:
>
> (add-hook 'c-mode-hook
> 	(function (lambda ()
> 		(c-set-style "bsd")
> 		(setq c-basic-offset 4)
> 		(c-set-offset 0)

The above c-set-offset statement is obviously different from the one
you get after C-x ESC ESC.

Please try the one from C-x ESC ESC.
-- 
Ambibibentists unite!

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

* Re: C formatting
  2002-12-28 12:52   ` Oodini
  2002-12-28 13:50     ` Kai Großjohann
@ 2002-12-28 13:53     ` Kai Großjohann
  1 sibling, 0 replies; 16+ messages in thread
From: Kai Großjohann @ 2002-12-28 13:53 UTC (permalink / raw)


Oodini <svdbg@free.fr> writes:

> and then what what you said:
>      C-x C-o

C-c C-o, not C-x C-o...

> I get the the statement
>      Syntactic symabol to change: substatement

I get substatement-open, not substatement.  Did you really try it on
a line which has a brace in it?

> I hit Enter...
>      substatement offset (default +):
> I put 0, and then I get the *wanted behaviour*.
>      C-x ESC ESC
>      redo (c-set-offset (quote substatement) 0 nil)


-- 
Ambibibentists unite!

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

end of thread, other threads:[~2002-12-28 13:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-28  0:17 C formatting Oodini
2002-12-28  0:39 ` Bijan Soleymani
2002-12-28 11:47   ` Oodini
2002-12-28 11:50     ` Oodini
2002-12-28 12:32       ` Jesper Harder
2002-12-28 13:05     ` Kai Großjohann
2002-12-28 13:13       ` Oodini
2002-12-28  1:11 ` chris.danx
2002-12-28 12:31   ` Oodini
2002-12-28 12:57     ` chris.danx
2002-12-28 13:03       ` Oodini
2002-12-28 13:03     ` Kai Großjohann
2002-12-28 11:05 ` Kai Großjohann
2002-12-28 12:52   ` Oodini
2002-12-28 13:50     ` Kai Großjohann
2002-12-28 13:53     ` Kai Großjohann

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.