all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to disable multi-line string literal in c-mode and c++-mode?
@ 2009-08-18 15:21 wewwew
  2009-08-18 19:35 ` Alan Mackenzie
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: wewwew @ 2009-08-18 15:21 UTC (permalink / raw)
  To: help-gnu-emacs

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?

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.

Appreciate any help.

-Wenguang


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to disable multi-line string literal in c-mode and c++-mode?
  2009-08-18 15:21 How to disable multi-line string literal in c-mode and c++-mode? wewwew
@ 2009-08-18 19:35 ` Alan Mackenzie
       [not found] ` <mailman.4853.1250623941.2239.help-gnu-emacs@gnu.org>
  2009-08-19  8:49 ` Anselm Helbig
  2 siblings, 0 replies; 5+ messages in thread
From: Alan Mackenzie @ 2009-08-18 19:35 UTC (permalink / raw)
  To: wewwew; +Cc: help-gnu-emacs

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.

> 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. 

> Appreciate any help.

> -Wenguang

-- 
Alan Mackenzie (Nuremberg, Germany).




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to disable multi-line string literal in c-mode and c++-mode?
       [not found] ` <mailman.4853.1250623941.2239.help-gnu-emacs@gnu.org>
@ 2009-08-18 20:40   ` wewwew
  2009-08-18 21:35     ` Peter Milliken
  0 siblings, 1 reply; 5+ messages in thread
From: wewwew @ 2009-08-18 20:40 UTC (permalink / raw)
  To: help-gnu-emacs

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).



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to disable multi-line string literal in c-mode and c++-mode?
  2009-08-18 20:40   ` wewwew
@ 2009-08-18 21:35     ` Peter Milliken
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Milliken @ 2009-08-18 21:35 UTC (permalink / raw)
  To: wewwew; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 4649 bytes --]

Noweb is a Literate Programming (minor) mode written for Emacs by Norman
Ramsey (http://www.cs.tufts.edu/~nr/noweb/) - I used it about 7 years ago
and only recently (8 days ago :-)) revisited the latest version. The major
appeal of noweb over other literate programming modes (if they exist) is
that it is language independent i.e. you can do literate programming in
Python, C/C++, Pascal or whatever strikes your fancy. This is what first
attracted me to it and still brings me back to it.

I haven't looked into this, but I believe what is happening is that noweb
mode allows Emacs to switch between major modes as point moves through the
buffer (Latex and whatever the major mode is for the target code). Which is
a great idea and makes things very convenient for the programmer as we all
depend on major mode features for almost everything we do, so latex features
are required for the documentation portions and C/C++ features for the code
portion (in wew's case). Unfortunately the major mode (C/C++ in this case)
scans the ENTIRE file when making syntax highlights etc. Similarly, Latex
mode (when it is in force) scans the entire buffer and makes its syntax
highlights. This is where the mix-up is happening.
What is really desired is that whatever process is used for the scanning,
that the major mode be "switched" as the region changes between Latex and
whatever code mode is being used and each applied to the appropriate region
ONLY i.e. as the scanning process passes through a section that is Latex it
performs Latex syntax highlighting and as it passes through the region that
is code that it performs the appropriate code.

I have never looked at what process is involved in syntax highlighting a
buffer but the only true fix to this problem is to have the scanning process
match the major mode highlighting with the appropriate region as the scan
proceeds i.e. as it is travelling through a latex region then use latex
highlighting and as it is travelling through a code region use whatever that
major mode highlighting needs.

Anything else is probably just a waste of time as it will never be "perfect"
and will only lead to frustration. So my suggestion is to look into how the
scanning process works and try and isolate the appropriate buffer regions to
the appropriate major mode.

Hope this makes sense :-)

Peter

On Wed, Aug 19, 2009 at 6:40 AM, wewwew <wew036@cs.usask.ca> wrote:

> 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).
>
>

[-- Attachment #2: Type: text/html, Size: 5899 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to disable multi-line string literal in c-mode and c++-mode?
  2009-08-18 15:21 How to disable multi-line string literal in c-mode and c++-mode? wewwew
  2009-08-18 19:35 ` Alan Mackenzie
       [not found] ` <mailman.4853.1250623941.2239.help-gnu-emacs@gnu.org>
@ 2009-08-19  8:49 ` Anselm Helbig
  2 siblings, 0 replies; 5+ messages in thread
From: Anselm Helbig @ 2009-08-19  8:49 UTC (permalink / raw)
  To: help-gnu-emacs

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?
> 
> 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.

You could try one of the packages mentioned on this page:

  http://www.emacswiki.org/emacs/MultipleModes

Good luck!

Anselm


-- 
Anselm Helbig 
mailto:anselm.helbig+news2009@googlemail.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-08-19  8:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-18 15:21 How to disable multi-line string literal in c-mode and c++-mode? wewwew
2009-08-18 19:35 ` Alan Mackenzie
     [not found] ` <mailman.4853.1250623941.2239.help-gnu-emacs@gnu.org>
2009-08-18 20:40   ` wewwew
2009-08-18 21:35     ` Peter Milliken
2009-08-19  8:49 ` Anselm Helbig

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.