* cc-mode and continuing a for loop statement over two lines
@ 2008-02-28 6:40 nullius.filius
2008-02-28 17:46 ` Nikolaj Schumacher
[not found] ` <mailman.8046.1204220786.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 3+ messages in thread
From: nullius.filius @ 2008-02-28 6:40 UTC (permalink / raw)
To: help-gnu-emacs
I would like to indent twice if I have to continue a
for loop statement onto more than one line. For example,
as in the following code-
for (vector<int>::iterator iter(data.begin());
iter != data.end(); ++iter)
{
// do something
}
This is so cc-mode formats like the ANSI predefined style
in astyle.
This is the code in my dot emacs (boosted from elsewhere).
I have not found a variable for tweaking continuation lines
from inside for loop statements.
------------------------------------------------------------------------
(defconst c-indentation 4)
(defvar my-c-style
`((c-basic-offset . ,c-indentation)
(c-tab-always-indent . t)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist . ((substatement-open . (before
after))
(brace-list-open)
(brace-list-close)
(brace-list-intro)
(brace-entry-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close .
c-lineup-arglist-close-under-
paren)
(substatement-open . 0)
(innamespace . nil)
(label . nil)
(block-open . 0)
(inline-open . 0)
(template-args-cont .
c-lineup-template-args)
(inher-cont . c-lineup-multi-
inher)
(statement-cont . (c-lineup-math
++))
(knr-argdecl-intro . -)))
(c-echo-syntactic-information-p . t)
)
"My C Programming Style")
(defun my-c-mode-common-hook ()
(c-add-style "PERSONAL" my-c-style t))
(add-hook 'c++-mode-hook 'my-c-mode-common-hook)
------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: cc-mode and continuing a for loop statement over two lines
2008-02-28 6:40 cc-mode and continuing a for loop statement over two lines nullius.filius
@ 2008-02-28 17:46 ` Nikolaj Schumacher
[not found] ` <mailman.8046.1204220786.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 3+ messages in thread
From: Nikolaj Schumacher @ 2008-02-28 17:46 UTC (permalink / raw)
To: nullius.filius; +Cc: help-gnu-emacs
nullius.filius@gmail.com wrote:
> I would like to indent twice if I have to continue a
> for loop statement onto more than one line. For example,
> as in the following code-
>
> for (vector<int>::iterator iter(data.begin());
> iter != data.end(); ++iter)
> {
> // do something
> }
Here's what I came up with:
(defun indent-for-cont (langelem)
(let ((beg (car (c-declaration-limits nil))))
(if (equal "for" (buffer-substring-no-properties beg (+ 3 beg)))
'+
0)))
Then add this:
(statement . indent-for-cont)
to your c-offsets-alist.
regards,
Nikolaj Schumacher
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <mailman.8046.1204220786.18990.help-gnu-emacs@gnu.org>]
* Re: cc-mode and continuing a for loop statement over two lines
[not found] ` <mailman.8046.1204220786.18990.help-gnu-emacs@gnu.org>
@ 2008-02-29 2:05 ` nullius.filius
0 siblings, 0 replies; 3+ messages in thread
From: nullius.filius @ 2008-02-29 2:05 UTC (permalink / raw)
To: help-gnu-emacs
Thank you Nikolaj,
I could not get your code snippet to double indent. I like
the concept behind your hack, and I will play around with
it because I'm sure it will work.
Nikolaj Schumacher wrote:
> nullius.filius@gmail.com wrote:
>
> > I would like to indent twice if I have to continue a
> > for loop statement onto more than one line. For example,
> > as in the following code-
> >
> > for (vector<int>::iterator iter(data.begin());
> > iter != data.end(); ++iter)
> > {
> > // do something
> > }
>
> Here's what I came up with:
>
> (defun indent-for-cont (langelem)
> (let ((beg (car (c-declaration-limits nil))))
> (if (equal "for" (buffer-substring-no-properties beg (+ 3 beg)))
> '+
> 0)))
>
> Then add this:
> (statement . indent-for-cont)
> to your c-offsets-alist.
>
>
> regards,
> Nikolaj Schumacher
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-02-29 2:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-28 6:40 cc-mode and continuing a for loop statement over two lines nullius.filius
2008-02-28 17:46 ` Nikolaj Schumacher
[not found] ` <mailman.8046.1204220786.18990.help-gnu-emacs@gnu.org>
2008-02-29 2:05 ` nullius.filius
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.