From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Le Wang" Newsgroups: gmane.emacs.help Subject: Re: Adding keywords to cc-mode Date: 23 Jun 2006 21:37:51 -0700 Organization: http://groups.google.com Message-ID: <1151123871.218171.119930@c74g2000cwc.googlegroups.com> References: <1151119358.514309.37040@g10g2000cwb.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: sea.gmane.org 1151124048 1499 80.91.229.2 (24 Jun 2006 04:40:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 24 Jun 2006 04:40:48 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 24 06:40:45 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ftzwp-0004TY-TS for geh-help-gnu-emacs@m.gmane.org; Sat, 24 Jun 2006 06:40:44 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ftzwp-0004KC-Do for geh-help-gnu-emacs@m.gmane.org; Sat, 24 Jun 2006 00:40:43 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!c74g2000cwc.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 46 Original-NNTP-Posting-Host: 131.107.0.74 Original-X-Trace: posting.google.com 1151123876 6311 127.0.0.1 (24 Jun 2006 04:37:56 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 24 Jun 2006 04:37:56 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; WOW64; SV1; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 RED-PRXY-24 Complaints-To: groups-abuse@google.com Injection-Info: c74g2000cwc.googlegroups.com; posting-host=131.107.0.74; posting-account=j4OimgwAAAALo-2szSZvOyX5OE1uyIeS Original-Xref: shelby.stanford.edu gnu.emacs.help:140007 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:35631 Archived-At: 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: (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) Add hook as appropriate for C++/CLI files. Someone please still chime in with the "proper" solution. -- Le