From: Peter <peter.milliken@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: help using/understanding syntax tables
Date: Sat, 4 Feb 2017 21:24:29 -0800 (PST) [thread overview]
Message-ID: <43e46d85-5b39-47b6-b42b-5e8c748b33f0@googlegroups.com> (raw)
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
next reply other threads:[~2017-02-05 5:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-05 5:24 Peter [this message]
2017-02-05 8:18 ` help using/understanding syntax tables Helmut Eller
2017-02-06 20:12 ` Peter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43e46d85-5b39-47b6-b42b-5e8c748b33f0@googlegroups.com \
--to=peter.milliken@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.