From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: PJ Weisberg Newsgroups: gmane.emacs.help Subject: Re: c-style-alist Date: Sat, 25 Sep 2010 15:07:31 -0700 Message-ID: References: <4C9E00FF.9040105@easy-emacs.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1285452551 18861 80.91.229.12 (25 Sep 2010 22:09:11 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 25 Sep 2010 22:09:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Sep 26 00:09:10 2010 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.69) (envelope-from ) id 1Ozcv3-0005AT-0y for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Sep 2010 00:09:09 +0200 Original-Received: from localhost ([127.0.0.1]:54200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ozcut-0004zC-V4 for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Sep 2010 18:08:24 -0400 Original-Received: from [140.186.70.92] (port=50078 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OzcuB-0004w3-2X for help-gnu-emacs@gnu.org; Sat, 25 Sep 2010 18:07:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ozcu7-0004t8-He for help-gnu-emacs@gnu.org; Sat, 25 Sep 2010 18:07:36 -0400 Original-Received: from smtpauth22.prod.mesa1.secureserver.net ([64.202.165.44]:54389) by eggs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Ozcu7-0004se-7I for help-gnu-emacs@gnu.org; Sat, 25 Sep 2010 18:07:35 -0400 Original-Received: (qmail 23804 invoked from network); 25 Sep 2010 22:07:32 -0000 Original-Received: from unknown (209.85.214.169) by smtpauth22.prod.mesa1.secureserver.net (64.202.165.44) with ESMTP; 25 Sep 2010 22:07:32 -0000 Original-Received: by iwn33 with SMTP id 33so5692314iwn.0 for ; Sat, 25 Sep 2010 15:07:31 -0700 (PDT) Original-Received: by 10.42.6.75 with SMTP id 11mr1617504icz.50.1285452451552; Sat, 25 Sep 2010 15:07:31 -0700 (PDT) Original-Received: by 10.42.5.138 with HTTP; Sat, 25 Sep 2010 15:07:31 -0700 (PDT) In-Reply-To: <4C9E00FF.9040105@easy-emacs.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 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:75013 Archived-At: On Sat, Sep 25, 2010 at 7:02 AM, Andreas R=F6hler wrote: > Am 25.09.2010 13:54, schrieb Andrea Crotti: >> I solved =A0making that mode a derived-mode from cc-mode. >> Then I created another derived-mode for c++ files used by omnetpp, but >> I'm struggling to make it automatically enabled. >> >> It's very very simple >> --8<---------------cut here---------------start------------->8--- >> (require 'derived) >> >> (define-derived-mode cpp-omnet-mode c++-mode "C++ Omnet mode" >> =A0 "Major mode for editing c++ files used with omnet++" >> =A0 ) >> >> (provide 'cpp-omnet-mode) >> --8<---------------cut here---------------end--------------->8--- >> >> and I thought I could do simply something like >> --8<---------------cut here---------------start------------->8--- >> =A0 ;; Look for the file .ini or the header inclusion >> =A0 (defun is-omnet-cpp-file () >> =A0 =A0 (if >> =A0 =A0 =A0 =A0 (or (file-exists-p "omnetpp.ini") >> =A0 =A0 =A0 =A0 =A0 =A0 (search-forward "")) >> =A0 =A0 =A0 =A0 (cpp-omnet-mode))) >> >> =A0 ;FIXME: Not working correctly yet, because it goes in infinite loop >> =A0 ;; (add-hook 'c++-mode-hook 'is-omnet-cpp-file) >> --8<---------------cut here---------------end--------------->8--- >> >> But it's not fine, since it will evaluate infinitely this hook. >> Another possibility would be to use "find-file-hook", but it doesn't >> really make sense because the files possible are a subset of c++ files. >> >> How can I make it non recurse keeping this? >> Or some other suggestions? > > Maybe like this: > > (defun is-omnet-cpp-file () > =A0(or (cpp-omnet-mode) > =A0 =A0 =A0(if > =A0 =A0 =A0 =A0 =A0(or (file-exists-p "omnetpp.ini") > =A0 =A0 =A0 =A0 =A0 =A0 =A0(search-forward "")) > =A0 =A0 =A0 =A0 =A0(cpp-omnet-mode)))) > > There is no path with "omnetpp.ini", which however should not cause a > infinite. It looks to me like what's happening is that in the hook it switches to cpp-omnet-mode, and since that's derived from c++-mode it results in c++-mode-hooks getting run again, so it again switches to cpp-omnet-mode and runs c++-mode-hooks, ad infinitum. I'm not an expert and I'm sure there's a better way to do it, but one way I could suggest is to set a buffer-local variable to mark that you're switching to cpp-omnet-mode, and don't switch to cpp-omnet-mode again if it's already set.