Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help using/understanding syntax tables

30 views
Skip to first unread message

Peter

unread,
Feb 5, 2017, 12:24:30 AM2/5/17
to
I want to be able to search a buffer to detect the text within {}/[] pairings - and nothing else. I could use regexp searches of course, but I thought it would be a good learning opportunity to use syntax tables (and the scan-lists function).

What I have tried is copying the default syntax table, changing every entry to be a word-constituent and then adding the appropriate open parenthesis characters i.e.

(defvar my-syntax-table (copy-syntax-table (standard-syntax-table)))

(map-char-table #'(lambda (key value)
(modify-syntax-entry key "w" my-syntax-table))
(syntax-table))

(modify-syntax-entry ?\{ "(}" my-syntax-table)
(modify-syntax-entry ?\} "){" my-syntax-table)
(modify-syntax-entry ?[ "(]" my-syntax-table)
(modify-syntax-entry ?] ")[" my-syntax-table)

my code then starts with:

(with-syntax-table my-syntax-table
.
.
.



This seems to work OK finding {}/[] pairings, but for some reason, it also detects <> pairings - which I do not want at all.

I was not sure of the use of "(syntax-table)" in the 'map-char-table statement - I tried changing it to be "my-syntax-table" but it made no difference to the results.

Any help/clarification would be appreciated - thanks
Peter

Helmut Eller

unread,
Feb 5, 2017, 3:18:35 AM2/5/17
to
On Sat, Feb 04 2017, Peter wrote:

> I was not sure of the use of "(syntax-table)" in the 'map-char-table
> statement - I tried changing it to be "my-syntax-table" but it made no
> difference to the results.

(syntax-table) returns the current syntax-table, i.e. the syntax-table
of the current buffer. In your example, map-char-table iterates over
the current syntax-table but then modify-syntax-entry modifies
my-syntax-table. So it looks OK. Though, you could change the entire
range without iteration like so:

(modify-syntax-entry (cons 0 (max-char)) "w" my-syntax-table)

I don't know why < and > don't work as they should.

Helmut

Peter

unread,
Feb 6, 2017, 3:12:03 PM2/6/17
to
Thanks Helmut
0 new messages