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

* Re: help using/understanding syntax tables
  2017-02-05  5:24 help using/understanding syntax tables Peter
@ 2017-02-05  8:18 ` Helmut Eller
  2017-02-06 20:12   ` Peter
  0 siblings, 1 reply; 3+ messages in thread
From: Helmut Eller @ 2017-02-05  8:18 UTC (permalink / raw)
  To: help-gnu-emacs

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


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

* Re: help using/understanding syntax tables
  2017-02-05  8:18 ` Helmut Eller
@ 2017-02-06 20:12   ` Peter
  0 siblings, 0 replies; 3+ messages in thread
From: Peter @ 2017-02-06 20:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Sunday, February 5, 2017 at 7:18:35 PM UTC+11, Helmut Eller wrote:
> 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

Thanks Helmut


^ 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.