From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Peter Milliken Newsgroups: gmane.emacs.help Subject: Re: How to disable multi-line string literal in c-mode and c++-mode? Date: Wed, 19 Aug 2009 07:35:24 +1000 Message-ID: <791153ba0908181435y2c9e1fbdp1a95a5c0276ffdf7@mail.gmail.com> References: <4a7f28df-9e34-4500-9038-199401f60d90@c1g2000yqi.googlegroups.com> <2307dce5-2043-446f-9073-2b9bc4d18cbc@l35g2000pra.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=000e0cd2149ed9cde40471714bf5 X-Trace: ger.gmane.org 1250631365 19767 80.91.229.12 (18 Aug 2009 21:36:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Aug 2009 21:36:05 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: wewwew Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 18 23:35:57 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MdWLV-0000pb-4z for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Aug 2009 23:35:57 +0200 Original-Received: from localhost ([127.0.0.1]:55636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MdWLU-0001gh-9d for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Aug 2009 17:35:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MdWL5-0001gY-OQ for help-gnu-emacs@gnu.org; Tue, 18 Aug 2009 17:35:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MdWL1-0001gG-Gf for help-gnu-emacs@gnu.org; Tue, 18 Aug 2009 17:35:31 -0400 Original-Received: from [199.232.76.173] (port=41611 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MdWL1-0001gD-Am for help-gnu-emacs@gnu.org; Tue, 18 Aug 2009 17:35:27 -0400 Original-Received: from rv-out-0708.google.com ([209.85.198.246]:11957) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MdWL0-0001Pk-P4 for help-gnu-emacs@gnu.org; Tue, 18 Aug 2009 17:35:27 -0400 Original-Received: by rv-out-0708.google.com with SMTP id c5so826689rvf.2 for ; Tue, 18 Aug 2009 14:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=JV2oDgt/1Rd+RMd39vmDdgTPrJ6Iu6bEIXHKIhQyYew=; b=h2DBY4Ad4omMs9WjRLz74QCJvgCBNjXe+AYJXm/A2FBz0x6DFOkKe6kC+oBcd19t+S M16dysXpapxgiW4B/kqyMBCdClQ0EQ0Oc+YGWtm3S9eZ2/vmsHhfSeUtkoC5dDtlvTar O4s4Hm77zmXVEztBIW8AglPWNmIdVT+LVaqWw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=fjEtSy4pgw7Px07q1Y+gr3qfwqHPCjxwe7ZhqSyHIN9ovo79WLwiJyy8NB0UxHNdV6 zS2tmcp7mDxJdKme0ymM67rkfciz+GMyLYVDA7FGCVXaRXp41hHofjkWId3VxT2ZjUvt UUgl5tGsq+2XmTIqMkGD26e9NKfS4Gm8fO478= Original-Received: by 10.140.157.9 with SMTP id f9mr1854631rve.165.1250631324650; Tue, 18 Aug 2009 14:35:24 -0700 (PDT) In-Reply-To: <2307dce5-2043-446f-9073-2b9bc4d18cbc@l35g2000pra.googlegroups.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:67256 Archived-At: --000e0cd2149ed9cde40471714bf5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 wrote: > On Aug 18, 12:35 pm, Alan Mackenzie 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). > > --000e0cd2149ed9cde40471714bf5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Noweb is a Literate Programming (minor) mode written for Emacs by=A0Norman Ramsey (http://www.cs.tufts.edu/~nr/noweb/)=A0- I used it abou= t 7 years ago and only recently (8 days ago :-)) revisited the latest versi= on. The major appeal of noweb over other literate programming modes (if the= y exist) is that it is language independent i.e. you can do literate progra= mming 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 happen= ing 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 targ= et code). Which is a great idea and makes things very convenient for the pr= ogrammer as we all depend on major mode features for almost everything we d= o, 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 highligh= ts 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 cha= nges 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 passe= s through the region that is code that it performs the appropriate code.

I have never looked at what process is involved in synt= ax highlighting a buffer but the only true fix to this problem is to have t= he 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 wi= ll never be "perfect" and will only lead to frustration. So my su= ggestion 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 :-)

Pete= r=A0

On Wed, Aug 19, 2009 at 6:40 AM, wew= wew <wew036@cs.u= sask.ca> wrote:
On Aug 18, 12:35=A0pm, Al= an Mackenzie <a...@muc.de> wrote:<= br> > 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++-mo= de,
> > and treat the end of line as the end of string literal?
>
> This is not simple. =A0CC Mode uses the "syntax mechanism" o= f Emacs (See
> the chapter "Syntax Tables" in the Elisp manual if you'r= e interested),
> which does things like matching up parentheses, recognising comments a= nd,
> 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 givin= g
> them a "string" syntax-table property).
>
> You would need to modify CC Mode (by adding this option) to achieve th= is.

It is not clear to me how easy to do that. =A0Can I disable all strin= g
literals?

>
> > I am programming using noweb, where LaTeX and C++ sources are mix= ed
> > together. =A0When 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 literal= s. =A0I
> > would like to disable this multi-line string literals in c++-mode= .
>
> I don't know noweb. =A0Is there any easy and reliable way to recog= nise the
> LaTeX bits within the source file? =A0If so, maybe the mechanism used = to
> neutralize lines like
>
> =A0 =A0 #define QUOTE "
>
> could be adapted. =A0The above, fully legitimate, line used to cause t= he
> 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 >>=3D
// C/C++ code here
@

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

Thanks!

-Wenguang

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


--000e0cd2149ed9cde40471714bf5--