all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Lennart Borgman (gmail)" <lennart.borgman@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: CC Mode - syntactical can of worms.
Date: Thu, 31 Jan 2008 23:05:19 +0100	[thread overview]
Message-ID: <47A2461F.9030007@gmail.com> (raw)
In-Reply-To: <20080131220519.GA3770@muc.de>

Alan Mackenzie wrote:
>> CC-mode's job is fundamentally impossible.
> 
> Hey, don't be like that!  ;-)  Yes, people can deliberately break it with
> the likes of HELLO and WORLD, but the more modest aim of CC Mode, to deal
> properly with anything reasonable, is doable.
> 
> I think I can fix this by setting a neutral syntax-table property on
> anything obtrusive in a CPP construct.  Here's a first shot at doing
> that:
> 
> 
> ;; Set syntax table properties on a CPP (logical) line, so that it becomes
> ;; "syntactically neutral".  This means that lines such as:
> ;;
> ;;     #warning for isn't a keyword.
> ;;                     ^
> ;; and
> ;;
> ;;     #define RBRACE }
> ;;                    ^
> ;; won't interact syntactically with the rest of the file.
> (defun c-neutralize-CPP-line (beg end)
>   (let (s)
>     (while
> 	(progn
> 	  (setq s (parse-partial-sexp beg end -1))
> 	  (cond
> 	   ((< (nth 0 s) 0)		; found an unmated ),},]
> 	    (c-put-char-property (1- (point)) 'syntax-table '(1)) ; "punctuation".
> 	    t)
> 	   ((or (nth 3 s) (nth 4 s))	; In a string or comment.
> 	    (c-put-char-property (nth 8 s) 'syntax-table '(1))
> 	    t)
> 	   ((> (nth 0 s) 0)		; In a (,{,[
> 	    (c-put-char-property (nth 1 s) 'syntax-table '(1))
> 	    t)
> 	   (t nil))))))
> 


This is like watching a game of chess - without understanding the moves, 
but knowning that the players do.




      reply	other threads:[~2008-01-31 22:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-31 11:45 CC Mode - syntactical can of worms Alan Mackenzie
2008-01-31 12:53 ` Andreas Schwab
2008-01-31 15:00 ` Stefan Monnier
2008-01-31 22:05   ` Alan Mackenzie
2008-01-31 22:05     ` Lennart Borgman (gmail) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47A2461F.9030007@gmail.com \
    --to=lennart.borgman@gmail.com \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.