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

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

Re: formatting C++ code which includes SWIG macros


From: Alan Mackenzie
Subject: Re: formatting C++ code which includes SWIG macros
Date: Sat, 18 May 2013 16:26:38 +0000 (UTC)
User-agent: tin/1.9.6-20101126 ("Burnside") (UNIX) (FreeBSD/8.4-PRERELEASE (amd64))

Hi, Doug.

Douglas Meyer <dbmeyer030@gmail.com> wrote:
> Hi folks,

> I've entered into an existing project that is written in C++.

I think the problem is that it's _not_ C++, rather it's an idiosyncratic
extension, which (ab)uses the modulus operator to introduce a new type of
macro.

> The style is nearly the same as google-c-style.el, and so I'm using
> that with minor changes in emacs 23.1.1.

> The fly in the ointment are SWIG macros used in some C++ files. Since
> emacs apparently knows nothing about SWIG being used in other source
> files, the C++ formatting gets confused. Of course, this is because
> emacs is using what rules it has to interpret the code. No fault on
> emacs' part.

Presumably, there's some sort of preprocessor which converts these SWIG
files to standard C++ before they get to the compiler

> [If you're curious, I've put sketch of the kind of things I'm dealing
> with in the P.S.]

> I'm searching for a solution, and haven't yet found anybody who's
> already dealt with this. Unfortunately, I'm not a lisp writer.

Let me guess a few things about SWIG:
1. All SWIG keywords start with a %.
2. There are several such keywords rather than many.
3. A SWIG construct is always on a line of its own.
4. A SWIG construct is never continued onto a new line by \ (or anything
  else).
5. Standard C++ lines are syntactically independent of SWIG lines.

> Any suggestions about how this might be able to be readily handled?

To do this properly would involve extending C++ Mode and this would be an
enormous amount of work.  A more realistic approach might be to treat all
SWIG lines as being terminated by a "virtual semicolon" thus preventing
lines like "class MyClass" as being parsed as the continuation of a SWIG
line.

I could probably manage to do this for you, but first, could you confirm
(or correct) my 5 guesses above, and supply a list of SWIG keywords.

> Thanks for your time and expertise.

No problem!

> Blessings,
> Doug

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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