[Top][All Lists]

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

Re: syntax-after

From: Juri Linkov
Subject: Re: syntax-after
Date: Sat, 13 Nov 2004 12:57:54 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

Richard Stallman <address@hidden> writes:
>     It seems really gratuitous.  There are already 2 ways to represent the
>     syntax info of a char: as a cons cell and as a string.  Both are 
> documented
>     in the elisp manual.
>     The above change introduces yet a third representation, and an 
> undocumented
>     one at that.  Was that really necessary?
> It is not new.  My change makes it compatible with char-syntax, which
> is why I did it.  It is also more comparible with the way
> modify-syntax-entry works, since the same character is used now by both.
> This change reduces the number of representations of the syntax by
> one, as far as I know.  Or is there some other function that uses the
> old representation of syntax-after?  If so, perhaps it should be
> changed too.

Actually, with the change in `syntax-after' there are 4 representations now:

modify-syntax-entry  aref(syntax-table)  char-syntax  syntax-after      
"w"                  (2)                 ?w           (?w)
"w p"                (1048578)           ?w           args-out-of-range
". 124b"             (2818049)           ?.           args-out-of-range
"(]"                 (4 . ?\])           ?\(          (?\( . ?\])

(Note that `syntax-after' fails with args-out-of-range on some syntaxes.)

It seems you wanted to add syntax flags to the returned value which
are not available from `char-syntax'.

I think a better solution that would reduce the number of
representations is to implement a new function `syntax-to-string'
returning a syntax string (e.g. ". 124b").  All flags can be accessed
from this string easily either with a regexp or with `substring' or `aref'
when needed.

As I see in the Emacs source tree `char-syntax' is mostly used
in combination with `char-after':

    (eq (char-syntax (char-after point)) ?w)

where only syntax class character is needed, and not flags.

For such cases `syntax-after' would serve as a replacement to make
code simpler:

(defun syntax-after (point)
  (char-syntax (char-after point)))

>     I just saw that the above change caused Juri to install a fix to
>     descr-text.el that replaces a call to syntax-after with a copy of its
>     (previous) body.
> That is strange, I searched for all the calls and only found them in
> paren.el.

Since `describe-char' calls `internal-describe-syntax-value' which
accepts the internal syntax representation, I think no special
function for that code is needed, because there are too few cases
where the internal syntax representation is used (another one I know
is `describe-syntax' command).

Juri Linkov

reply via email to

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