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

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

Re: How to disable multi-line string literal in c-mode and c++-mode?


From: wewwew
Subject: Re: How to disable multi-line string literal in c-mode and c++-mode?
Date: Tue, 18 Aug 2009 13:40:16 -0700 (PDT)
User-agent: G2/1.0

On Aug 18, 12:35 pm, Alan Mackenzie <a...@muc.de> wrote:
> Hi,
>
> On Tue, Aug 18, 2009 at 08:21:01AM -0700, wewwew wrote:
> > Hi,
> > How can I disable multi-line string literals in c-mode and c++-mode,
> > and treat the end of line as the end of string literal?
>
> This is not simple.  CC Mode uses the "syntax mechanism" of Emacs (See
> the chapter "Syntax Tables" in the Elisp manual if you're interested),
> which does things like matching up parentheses, recognising comments and,
> in particular, recognising strings.
>
> To modify this string recognition, you'd have to identify the EOLs which
> act as string terminators and individually mark them as such (by giving
> them a "string" syntax-table property).
>
> You would need to modify CC Mode (by adding this option) to achieve this.

It is not clear to me how easy to do that.  Can I disable all string
literals?

>
> > I am programming using noweb, where LaTeX and C++ sources are mixed
> > together.  When editing the code part, the buffer uses c++-mode, but
> > any single quote in the text is treated as start or end of string
> > literal, so many of my code chunks are rendered as string literals.  I
> > would like to disable this multi-line string literals in c++-mode.
>
> I don't know noweb.  Is there any easy and reliable way to recognise the
> LaTeX bits within the source file?  If so, maybe the mechanism used to
> neutralize lines like
>
>     #define QUOTE "
>
> could be adapted.  The above, fully legitimate, line used to cause the
> following lines to be fontified as strings.

I could also put a LaTeX comment in the text to do this:

%'

However, I would prefer not to use such hacks, because whenever I add/
remove quote in LaTeX text, the whole font colors of C/C++ code is
messed up again.

All C/C++ code are within such blocks:

<< some text >>=
// C/C++ code here
@

Where the "<<" and "@" always start on the first column.  Ideally, C/C+
+-mode should only fontify chunks within the "<<" and "@".  Is that
possible?

Thanks!

-Wenguang

>
> > Appreciate any help.
> > -Wenguang
>
> --
> Alan Mackenzie (Nuremberg, Germany).



reply via email to

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