help-gnu-emacs
[Top][All Lists]
Advanced

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

extending c-mode


From: Laurent Deniau
Subject: extending c-mode
Date: Fri, 15 Dec 2006 15:03:28 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060607 Debian/1.7.12-1.2

Dear all,

I have been through the cc-mode documentation and it seems that what I would like to do is not so obvious, at least for me, while I am sure that there is a simple way to do it with cc-mode. My problem concerns both highlight and indentation extension of the c-mode since my code is pure ISO C99 code and therefore I would like to keep the default highlights and indentation of C.

I have the following valid syntax (inspired from Objective-C) which defines a multimethod:

**Simple version:

defmethod(ret-type, method-name, receiver, argtype)
  // C code ...
endmethod

**Advanced version:

defmethod(ret-type,
          (method-name, alt-next-method-name),
          (receiver1, receiver2),
          (argtype1)argname1, (argtype2)argname2)
  // C code...
endmethod

**Simple uncommon version:

defmethod(ret-type, (method-name), (receiver), (argtype))
  // C code ...
endmethod

where
 - ret-type and argtype are C types or typedef like void, int or int*
 - method-name, alt-next-method-name, argname1 and argname2 are all
   user-defined valid C tokens, that is [A-Za-z_][A-Za-z0-9_]*
 - parentheses around method-name are required only if a
   alt-next-method-name is specified.
 - parentheses around receiver are required only if more than one
   receiver is specified.
 - parentheses around argtype are required only if an argname is
   specified.

Here are the points:

1) Indentation:
   I would like defmethod() to behave like { and endmethod like }.

2) Highlight:
   I would like to color the foreground of each of the following points:
    - the keywords defmethod and endmethod.
    - method-name whether alt-next-method-name is present or not
      taking care of the presence of the enclosing ().
    - receivers whether there is 1, 2, 3 or 4 receivers
      taking care of the presence of the enclosing ().
    - argtypes whether argname is present or not
      taking care of the presence of the enclosing ().

Since the arguments of defmethod look-like a list (at least this is how it is processed by the cpp defmethod() macro), I expect that it should be easy to process it by emacs-lisp.

So, what should I put in my .emacs to make these points effective? Since I am not an expect in emacs programming (I know a bit Lisp) and I will have to extend the answer to the rest of my syntax, a clear and simple example/code would be very helpful.

Any help will be very appreciated. Thanks.

a+, ld.


reply via email to

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