From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: C++ Indentation and access-labels Date: Fri, 18 Sep 2009 22:12:18 +0000 Message-ID: <20090918221218.GA5781@muc.de> References: <52a7da0f0909140727i24f47eaem8a36684ef10502f9@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1253311761 1317 80.91.229.12 (18 Sep 2009 22:09:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 18 Sep 2009 22:09:21 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: marc.duerner@gmail.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Sep 19 00:09:14 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Moldi-0001lA-78 for geh-help-gnu-emacs@m.gmane.org; Sat, 19 Sep 2009 00:09:14 +0200 Original-Received: from localhost ([127.0.0.1]:59182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Moldh-00061a-L9 for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Sep 2009 18:09:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MoldM-00061I-Vq for help-gnu-emacs@gnu.org; Fri, 18 Sep 2009 18:08:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MoldI-000604-4m for help-gnu-emacs@gnu.org; Fri, 18 Sep 2009 18:08:52 -0400 Original-Received: from [199.232.76.173] (port=53261 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MoldI-0005zz-1u for help-gnu-emacs@gnu.org; Fri, 18 Sep 2009 18:08:48 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:2761 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MoldH-000817-EB for help-gnu-emacs@gnu.org; Fri, 18 Sep 2009 18:08:47 -0400 Original-Received: (qmail 10525 invoked by uid 3782); 18 Sep 2009 22:08:43 -0000 Original-Received: from acm.muc.de (pD9E23404.dip.t-dialin.net [217.226.52.4]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Sat, 19 Sep 2009 00:08:41 +0200 Original-Received: (qmail 6820 invoked by uid 1000); 18 Sep 2009 22:12:19 -0000 Content-Disposition: inline In-Reply-To: <52a7da0f0909140727i24f47eaem8a36684ef10502f9@mail.gmail.com> User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-operating-system: by monty-python.gnu.org: FreeBSD 4.6-4.9 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:68296 Archived-At: Hi, Marc! On Mon, Sep 14, 2009 at 04:27:11PM +0200, Marc Dürner wrote: > Hello, > I am trying to set up semantic indentation for C++ and can't find a way > to configure the following indentation rule: > class A > { > friend class X; > int x; > public: > A(); <=========== > ~A(); <=========== > }; > I want to have class members and friend declarations indented by one level > if no access-label is present. If an acces-label is present it should be > indented and the class members that follow that access-label should be > indented further. It seems the is no way to handle class memers differently > if they are following an access-label. In the example above 'x' and 'A();' > are both classified as inclass/topmost-intro. > Is there a way to configure this? No. There should be, though. The first member after "public:" ought to get a special syntactical symbol, say "protection-clause-intro", somewhat analagous to "statement-block-intro", the first statement inside a compound statement (brace block). Maybe I'll fix this sometime. (If the previous paragraph doesn't make sense, either ignore it or look it all up on page "Syntactic Symbols" in the CC Mode manual.) However, CC Mode is flexible enough for workarounds to be possible. So, for the meantime, here's a workaround. Put the file below somewhere convenient (I've called it ~/duerner.el; you probably want to byte compile it), and add this line to your .emacs: (eval-after-load "cc-mode" '(load-file "~/duerner.el)) [ or ................................................elc)) ] # File ~/duerner.el: ######################################################################### (defsubst md-at-inclass/topmost-intro (sintax) (and (eq (caar sintax) 'inclass) (eq (car (cadr sintax)) 'topmost-intro))) (defun md-ind-prot-class () "Give an extra level of indentation to class thingies under an access specifier, e.g.: public A(); <========== extra level of indentation. This should really be properly implemented in CC Mode, but it's not." (and (md-at-inclass/topmost-intro c-syntactic-context) (let (m-type) (when (save-excursion (back-to-indentation) ;; Go back one "statement" at a time till we reach a label or something ;; which isn't an inclass/topmost-intro (while (and (eq (setq m-type (c-beginning-of-statement-1)) 'previous) (md-at-inclass/topmost-intro (c-guess-basic-syntax)))) ;; Have we found "private:", "public": or "protected"? (and (eq m-type 'label) (looking-at (eval-when-compile (c-make-keywords-re nil (c-lang-const c-protection-kwds c++)))))) (save-excursion (back-to-indentation) (c-shift-line-indentation c-basic-offset)))))) (defun md-add-hook () (add-hook 'c-special-indent-hook 'md-ind-prot-class)) (add-hook 'c++-mode-hook 'md-add-hook) ######################################################################### The above is a fairly rough and ready hack. If it does something silly, please get back to me with a description of the failure. > regards, > Marc Sincerely, -- Alan Mackenzie (Nürnberg).