all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* help using/understanding syntax tables
@ 2017-02-05  5:24 Peter
  2017-02-05  8:18 ` Helmut Eller
  0 siblings, 1 reply; 3+ messages in thread
From: Peter @ 2017-02-05  5:24 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-06 20:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-05  5:24 help using/understanding syntax tables Peter
2017-02-05  8:18 ` Helmut Eller
2017-02-06 20:12   ` Peter

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.