help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: is there a human readable way to display syntax table?


From: Kevin Rodgers
Subject: Re: is there a human readable way to display syntax table?
Date: Fri, 17 Oct 2008 07:50:54 -0600
User-agent: Thunderbird 2.0.0.17 (Macintosh/20080914)

Xah wrote:
When i write a new mode from the ground up (not using derived-mode or
generic mode), how do i go about defining the syntax table?

For example, i'm writing a mode for the LSL language, which uses a
sytax like C/Java.

So, i start by copying example from text-mode:

(defvar text-mode-syntax-table
  (let ((st (make-syntax-table)))
    (modify-syntax-entry ?\" ".   " st)
    (modify-syntax-entry ?\\ ".   " st)
    ;; We add `p' so that M-c on 'hello' leads to 'Hello' rather than
'hello'.
    (modify-syntax-entry ?' "w p" st)
    st)
  "Syntax table used while in `text-mode'.")

In my case, the LSL is basically ascii based lang. So, do i go thru
each printable ascii char, and add a modify-syntax-entry for it using
the above template?

Another question... i tried to study syntax table, which is a char
table, which is a specialized vector with extra things ... not so easy
to understand... but looking at the syntax table for text mode, it has
some 800 entries. Is a syntax table meant to cover all unicode char?

From the "Syntax Basics" node of the Emacs Lisp manual:

A syntax table is a char-table (*note Char-Tables::).  The element at
index C describes the character with code C.  The element's value
should be a list that encodes the syntax of the character in question.

...

   A syntax table can inherit the data for some characters from the
standard syntax table, while specifying other characters itself.  The
"inherit" syntax class means "inherit this character's syntax from the
standard syntax table."  Just changing the standard syntax for a
character affects all syntax tables that inherit from it.

From the "Char-Tables" node:

A char-table is much like a vector, except that it is indexed by
character codes.  Any valid character code, without modifiers, can be
used as an index in a char-table.  You can access a char-table's
elements with `aref' and `aset', as with any array.  In addition, a
char-table can have "extra slots" to hold additional data not
associated with particular character codes.  Char-tables are constants
when evaluated.

...

 -- Function: make-char-table subtype &optional init
     Return a newly created char-table, with subtype SUBTYPE.  Each
     element is initialized to INIT, which defaults to `nil'.  You
     cannot alter the subtype of a char-table after the char-table is
     created.

     There is no argument to specify the length of the char-table,
     because all char-tables have room for any valid character code as
     an index.

(am avoiding copying from c mode's syntax table for the moment so i
get more understanding by doing more from the basics... the cc-mode
source seems much complex to dig ...)

--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

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