all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* cc-mode indentation puzzle
@ 2011-01-31 21:33 blue
  2011-02-01 14:13 ` Andy Moreton
       [not found] ` <mailman.1.1296570019.10637.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: blue @ 2011-01-31 21:33 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I have been using cc-mode for years to help me adhere
to our corporate C coding style guidelines.  However,
there is one corner case that I still haven't got working.

Our standard dictates that if a statement is continued to
another line, the continuation lines (or lines) must each be
indented four spaces from the column where the original
statement started.  I have c-basic-offset = 8, and
statement-cont = '*' (which computes to 4).  Most of the time
this works fine.  But, if the continuation includes a
function call, I get an additional indentation of four
spaces for the next line.  The relevant offsets are
arglist-intro, arglist-cont, and arglist-cont-nonempty,
which are all '*' as well.  (Setting these all to 0 doesn't
produce the correct result either).

Example:

Indentation I want:

a = b + c +
    d + e + f(1,
    2, 3);

Indentation I get:

a = b + c +
    d + e + f(1,
        2, 3);

Here is the c-offsets-alist I use:

(c-add-style "personal"
       '((c-basic-offset . 8)
	 (c-tab-always-indent . nil)
	 (c-comment-only-line-offset . (0 . 0))
	 (c-offsets-alist . ((statement-block-intro . +)
			     (inextern-lang . 0)
			     (knr-argdecl-intro . +)
			     (substatement-open . +)
			     (label . 0)
			     (statement-case-open . +)
			     (statement-cont . *)
			     (statement . 0)
			     (arglist-intro . *)
			     (arglist-cont . *)
			     (arglist-cont-nonempty . *)
			     (arglist-close . *)))))

I'm trying to find a "legitimate" way to do this, i.e.,
not hacking to cc-*.el files.


Any help is much appreciated -- thanks,

John





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

* Re: cc-mode indentation puzzle
  2011-01-31 21:33 cc-mode indentation puzzle blue
@ 2011-02-01 14:13 ` Andy Moreton
       [not found] ` <mailman.1.1296570019.10637.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Moreton @ 2011-02-01 14:13 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon 31 Jan 2011, blue@themarkjamesgroup.com wrote:

> Indentation I want:
>
> a = b + c +
>     d + e + f(1,
>     2, 3);
>
> Indentation I get:
>
> a = b + c +
>     d + e + f(1,
>         2, 3);

Have a look at (Info-goto-node "(ccmode)Line-Up Functions")

`c-lineup-assingnments' may help.

    AndyM




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

* Re: cc-mode indentation puzzle
       [not found] ` <mailman.1.1296570019.10637.help-gnu-emacs@gnu.org>
@ 2011-02-01 14:54   ` Pascal J. Bourguignon
  2011-02-01 16:46     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Pascal J. Bourguignon @ 2011-02-01 14:54 UTC (permalink / raw)
  To: help-gnu-emacs

Andy Moreton <andrewjmoreton@gmail.com> writes:

> On Mon 31 Jan 2011, blue@themarkjamesgroup.com wrote:
>
>> Indentation I want:
>>
>> a = b + c +
>>     d + e + f(1,
>>     2, 3);
>>
>> Indentation I get:
>>
>> a = b + c +
>>     d + e + f(1,
>>         2, 3);

You should want and get:

 a = b + c +
     d + e + f(1,
               2, 3);

instead.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


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

* Re: cc-mode indentation puzzle
  2011-02-01 14:54   ` Pascal J. Bourguignon
@ 2011-02-01 16:46     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-02-01 16:46 UTC (permalink / raw)
  To: help-gnu-emacs

> You should want and get:

>  a = b + c +
>      d + e + f(1,
>                2, 3);

> instead.

Oh, yes.  But there's no arguing with corporate guidelines, I'm sure :-(
BTW, in some modes you may even get indentation like:

  a = b + c +
      d + e + f(1,
                2, 3) *
              4;

GNU coding style, would of course recommend to put the operators at the
beginning of line:
              
  a = b + c
      + d + e + f(1,
                  2, 3)
                * 4;

-- Stefan


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

end of thread, other threads:[~2011-02-01 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-31 21:33 cc-mode indentation puzzle blue
2011-02-01 14:13 ` Andy Moreton
     [not found] ` <mailman.1.1296570019.10637.help-gnu-emacs@gnu.org>
2011-02-01 14:54   ` Pascal J. Bourguignon
2011-02-01 16:46     ` Stefan Monnier

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.