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

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

help using/understanding syntax tables


From: Peter
Subject: help using/understanding syntax tables
Date: Sat, 4 Feb 2017 21:24:29 -0800 (PST)
User-agent: G2/1.0

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



reply via email to

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