From: "Le Wang" <l26wang@gmail.com>
Subject: Re: Adding keywords to cc-mode
Date: 23 Jun 2006 21:37:51 -0700 [thread overview]
Message-ID: <1151123871.218171.119930@c74g2000cwc.googlegroups.com> (raw)
In-Reply-To: 1151119358.514309.37040@g10g2000cwb.googlegroups.com
Le Wang wrote:
> Hi,
>
> I'd like to get the following to indent properly somehow.
>
> for each (i in collection) {
> // do stuff
> };
The problem is that the "each" starts another statement (I don't know
if I'm using the right word), so another indentation level is added.
The solution would be to recognize "for each" as a group or something
similar. I've come up with this hack that just decrements the indent:
<elisp>
(defvar le::for-each-regex
"for\\(?:[ \t\n]\\)+each")
(defun le::for-each-intro-indent (langelem)
(save-excursion
(goto-char (cdr langelem))
(if (looking-at for-each-regex)
0
'+)))
(defun le::for-each-close-indent (langelem)
(save-excursion
(goto-char (cdr langelem))
(if (looking-at for-each-regex)
'-
0)))
(c-set-offset 'statement-block-intro 'le::for-each-intro-indent)
(c-set-offset 'block-close 'le::for-each-close-indent)
</elisp>
Add hook as appropriate for C++/CLI files.
Someone please still chime in with the "proper" solution.
--
Le
next prev parent reply other threads:[~2006-06-24 4:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-24 3:22 Adding keywords to cc-mode Le Wang
2006-06-24 4:37 ` Le Wang [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-06-13 16:02 Stefan Arentz
[not found] ` <mailman.2114.1181760059.32220.help-gnu-emacs@gnu.org>
2007-06-13 20:03 ` Stefan Arentz
2007-06-13 20:06 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1151123871.218171.119930@c74g2000cwc.googlegroups.com \
--to=l26wang@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.