[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: c-style-alist

From: Andreas Röhler
Subject: Re: c-style-alist
Date: Sat, 25 Sep 2010 16:02:39 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv: Gecko/20100711 Thunderbird/3.0.6

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 ()
         (or (file-exists-p "omnetpp.ini")
             (search-forward "<omnetpp.h>"))

   ;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)
          (or (file-exists-p "omnetpp.ini")
              (search-forward "<omnetpp.h>"))

There is no path with "omnetpp.ini", which however should not cause a infinite.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]