emacs-devel
[Top][All Lists]
Advanced

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

Re: CC Mode - syntactical can of worms.


From: Lennart Borgman (gmail)
Subject: Re: CC Mode - syntactical can of worms.
Date: Thu, 31 Jan 2008 23:05:19 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

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 via email to

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