From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: c-style-alist Date: Sat, 25 Sep 2010 16:02:39 +0200 Message-ID: <4C9E00FF.9040105@easy-emacs.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1285423433 15510 80.91.229.12 (25 Sep 2010 14:03:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 25 Sep 2010 14:03:53 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Sep 25 16:03:52 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 1OzVLy-0000Hg-SH for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Sep 2010 16:03:51 +0200 Original-Received: from localhost ([127.0.0.1]:57060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OzVLy-0006N2-3P for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Sep 2010 10:03:50 -0400 Original-Received: from [140.186.70.92] (port=55421 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OzVLT-0006Ly-KZ for help-gnu-emacs@gnu.org; Sat, 25 Sep 2010 10:03:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OzVLL-0001th-NE for help-gnu-emacs@gnu.org; Sat, 25 Sep 2010 10:03:19 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.171]:64959) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OzVLL-0001tH-CE for help-gnu-emacs@gnu.org; Sat, 25 Sep 2010 10:03:11 -0400 Original-Received: from noname.home (brln-4dbc799d.pool.mediaWays.net [77.188.121.157]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MTveb-1PQHRC2emn-00RQUB; Sat, 25 Sep 2010 16:03:08 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 In-Reply-To: X-Provags-ID: V02:K0:zo+Cn4dYZIoUQgBQfKcRIK14DgSSWH49y42PSjmQFAi X0cjVs9IZqKrbOv7LtcFtcKQS9mXIznZN/R8o1n99j5CiHqcmL phEYxf+y/eSd93MA21uTIsllRGZx6re1YRPOqGl/xEvuIQ2kyk MFBX0VTwndsx6OPqmNq34++wI+Nl1J8NWLWyHm36ov3UtiTfEi 47yvLSkjkgnahc9xfZ3w4NeifHPnsD7cBEpYACcj4U= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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:75008 Archived-At: Am 25.09.2010 13:54, schrieb Andrea Crotti: > Andrea Crotti writes: > >> Supposing I have a new language (actually NED), and I already have some >> syntax highlighting. >> >> The only thing I want to add is a smarter indentation, and for that is >> quite similar to C++. >> >> Looking for possible answers I found out that in >> c-style-alist there is also for example python-mode, which is not a >> c-mode derivatives. >> >> Is that is the general way to define the correct the policy of spacing? >> And what if I define it as a derived mode even if it's quite different >> from the original c/c++ branch? > > I solved making 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" > "Major mode for editing c++ files used with omnet++" > ) > > (provide 'cpp-omnet-mode) > --8<---------------cut here---------------end--------------->8--- > > and I thought I could do simply something like > --8<---------------cut here---------------start------------->8--- > ;; Look for the file .ini or the header inclusion > (defun is-omnet-cpp-file () > (if > (or (file-exists-p "omnetpp.ini") > (search-forward "")) > (cpp-omnet-mode))) > > ;FIXME: Not working correctly yet, because it goes in infinite loop > ;; (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 () (or (cpp-omnet-mode) (if (or (file-exists-p "omnetpp.ini") (search-forward "")) (cpp-omnet-mode)))) There is no path with "omnetpp.ini", which however should not cause a infinite. Andreas -- https://code.launchpad.net/~a-roehler/python-mode https://code.launchpad.net/s-x-emacs-werkstatt/