unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to read a s-exp from a buffer?
@ 2015-06-25 18:59 Marcin Borkowski
  2015-06-25 19:18 ` Michael Heerdegen
  0 siblings, 1 reply; 2+ messages in thread
From: Marcin Borkowski @ 2015-06-25 18:59 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hi all,

so I want to write my own lexical analyzer of Elisp code (a very simple
one, of course).  Encouraged by Michael Heerdegen, I might want to start
with a simple metacircular evaluator (just as an exercise, further to be
transformed e.g. to a blog post for other learners of (Emacs) Lisp), and
then I’d like to write a more useful thing analyzing Elisp code.

So, I have an s-exp in the buffer, and I want to read it into
a variable, where it will become an Elisp list.  How do I do that?
Notice that I’d like to preserve all the funny things like (back)quotes
or commas, since I want to deal with them in my code.  That’s why
I assume that the ‘read’ function is not exactly what I’m looking for.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: How to read a s-exp from a buffer?
  2015-06-25 18:59 How to read a s-exp from a buffer? Marcin Borkowski
@ 2015-06-25 19:18 ` Michael Heerdegen
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Heerdegen @ 2015-06-25 19:18 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski <mbork@mbork.pl> writes:

> So, I have an s-exp in the buffer, and I want to read it into
> a variable, where it will become an Elisp list.  How do I do that?

Fortunately the reader can be invoked from Lisp via `read', just use
your buffer as STREAM argument with point at the beginning of the sexp
to read, e.g.

  (setq my-expr (read (current-buffer)))

That's already it.


Michael.




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

end of thread, other threads:[~2015-06-25 19:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-25 18:59 How to read a s-exp from a buffer? Marcin Borkowski
2015-06-25 19:18 ` Michael Heerdegen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).