Re: Accessing syntax tables flag info
- From: rgb <rbielaws@xxxxxx>
- Date: Tue, 19 Feb 2008 14:36:49 -0800 (PST)
On Feb 19, 2:27 am, "R. P. Dillon" <rpdil...@xxxxxxxxx> wrote:
I'm working on some elisp code to parse a buffer (expected to be run
in a buffer currently in a programming major mode). The purpose of
the function I am currently working on is to determine what characters
are used as comment characters in the current buffer's major mode.
This has led me to examine syntax tables. It seems I can get simple
comment starters (like ";" in lisp/scheme and "#" in python) by
guessing common comment characters and testing for a "<" result from
a (char-syntax) call. A reverse lookup would be nice ("give me all
characters whose class is "<") but I don't think that is going to
happen.
In a more complex area, I would like some way to access the character
flags in the syntax table (which would allow me to work with C, Java,
Scala style comments "//", "/*", "*/", etc.). In particular, I am
interested in the flags "1", "2", "3" and "4" as they are used in 2-
character comments. After reading the elisp manual, it seems there is
no way to access character flags in the syntax table. Is this
correct?
The best I have gotten so far is to read the code for describe-syntax,
which makes a call into the C source to describe-vector on the current
syntax table with an internal-describe-syntax-value. This will give me
some of the info I need, though I expect I should remove the describer
used in the describe-syntax call and write a function that does the
bit shifting on the vector values for the flags manually. Googling
has turned up nothing, so I was hoping some elisp hackers may have
some insight.
Cheers,
Rick
Having written several major modes for various programming
languages I'm sorry to say you're in for some bad news.
If you already know what major modes you will be working
with and you can make sure that the modes behave the way you
think they should then you're ok. But then again if you
know the modes you know the comment representation and you
could just maintain a table. That would be very much easier.
The problem is, not all major modes for programming
languages can use the syntax table. And even some that
could, don't. (Forth for example)
Here is a case where it can't work. TAL
!this is a comment! while this isn't !and this is a comment
but this isn't ! yet this IS
In this language I use a function to place comment start
syntax only on specific occurances of ! and put comment end
syntax on other instances of ! (and some instances of \n)
(Actually I think I used comment-fence but don't remember.)
An even worse example is Cobol because there need not be any
comment character present. Certain columns are implied
comments.
IOW the syntax table is totally unreliable as a generic
mechanism.
But, given that you are bent on finding a solution,
try this in various language modes.
M-: (re-search-forward "\\s<")
There are 3 characters used for specifying comment
syntax class:
< (comment start)
(comment end)! (generic comment delimiter)
Also look in the Emacs Lisp Reference
35.8 Syntax Table Internals
Good luck
.
- References:
- Accessing syntax tables flag info
- From: R. P. Dillon
- Accessing syntax tables flag info
- Prev by Date: Accessing syntax tables flag info
- Next by Date: Re: doing stuff with dates, anyone
- Previous by thread: Accessing syntax tables flag info
- Index(es):
Relevant Pages
|