Article View: gnu.emacs.bug
Article #87263[19.27]: parse-partial-sexp doesn't retain enough state info
From: Kevin Broadey
Date: Fri, 07 Oct 1994 11:56
Date: Fri, 07 Oct 1994 11:56
63 lines
2753 bytes
2753 bytes
I've been having trouble with font-lock-mode in C buffers not
fontifying strings that follow a "/**********/" type comment. For
example, try fontifying this program:-
----------------------------------------------------------------------
/****/
#include <stdio.h>
int main (int argc, char *argv[])
{
printf ("Hello world\n");
}
----------------------------------------------------------------------
The "Hello world\n" string doesn't get fontified.
I've traced the problem to parse-partial-sexp. It doesn't remember in
the returned `state' value that it has seen the first character of a
2-character comment terminator, so it thinks the rest of the buffer is
within a comment.
To prove this, use M-ESC to eval the following sexps in the
c-mode-buffer.
(setq state (parse-partial-sexp 1 6))
=> (0 nil nil nil t nil 0 nil)
This is the state up to, but not including, the terminating "/" of the
comment.
Now find the state to the end of the first line:-
(setq state2 (parse-partial-sexp 6 7 nil nil state))
=> (0 nil nil nil t nil 0 nil)
Note that (nth 4 state2) is `t'. This is wrong.
What font-lock does when it is within a comment is to go back to the
beginning, do (forward-comment 1) to skip over the comment, then
(skip-chars-backward " \t") to get to the real end of the comment. It
then uses parse-partial-sexp to work out the state immediately after
the comment.
The problem is that `comment-start-skip' matches everything up to the
last "*" in the comment, and this hits the bug in parse-partial-sexp.
I don't know how parse-partial-sexp should be fixed. Perhaps we need
another element in the STATE value, or perhaps (nth 4 state) could
indicate that the first character of a 2-character comment end has
been seen.
BTW what does (nth 7 state) mean? What is a "comment of style `b'"?
The version of the elisp manual I've got (for 19.19) only describes up
to (nth 6 state). Guess I need to track down the diffs.
--
Kevin
Technical Details
Message-ID:
<9410070831.AA11221@bartley>Path:
arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!redstone.interpath.net!ddsw1!panix!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!math.ohio-state.edu!cis.ohio-state.edu!bartley.DEmon.co.UK!KevinBShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,1367437b80bf355f,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1994-10-07 21:29:05 PST Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!redstone.interpath.net!ddsw1!panix!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!math.ohio-state.edu!cis.ohio-state.edu!bartley.DEmon.co.UK!KevinB From: KevinB@bartley.DEmon.co.UK (Kevin Broadey) Newsgroups: gnu.emacs.bug Subject: [19.27]: parse-partial-sexp doesn't retain enough state info Date: 7 Oct 1994 07:56:24 -0400 Organization: GNUs Not Usenet Lines: 63 Sender: daemon@cis.ohio-state.edu Approved: bug-gnu-emacs@prep.ai.mit.edu Distribution: gnu Message-ID: <9410070831.AA11221@bartley>