Obtaining a Lisp form from a file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Obtaining a Lisp form from a file

Udyant Wig-2
Is there a better way to write this?

(let ((foo-buffer (get-buffer-create "*foo*"))
      foo-form)
  (with-current-buffer foo-buffer
    (insert-file-contents foo-file))
  (setq foo-form (read foo-buffer))
  (kill-buffer foo-buffer)
  foo-form)

--
... while the ways of art are hard at the best, they will break you if
you go unsustained by belief in what you are trying to do.
                                -- Arthur Quiller-Couch

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Obtaining a Lisp form from a file

John Mastro
Udyant Wig <[hidden email]> wrote:
> Is there a better way to write this?
>
> (let ((foo-buffer (get-buffer-create "*foo*"))
>       foo-form)
>   (with-current-buffer foo-buffer
>     (insert-file-contents foo-file))
>   (setq foo-form (read foo-buffer))
>   (kill-buffer foo-buffer)
>   foo-form)

(with-temp-buffer
  (insert-file-contents file)
  (read (current-buffer)))

Hope that helps

        John

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Obtaining a Lisp form from a file

Emanuel Berg-4
In reply to this post by Udyant Wig-2
Udyant Wig wrote:

> Is there a better way to write this?
>
> (let ((foo-buffer (get-buffer-create "*foo*"))
> foo-form) (with-current-buffer foo-buffer
> (insert-file-contents foo-file)) (setq foo-form
> (read foo-buffer)) (kill-buffer foo-buffer)
> foo-form)

If nothing else, stop using the foobar stuff.
Always give proper names. I understand it is
just for testing but 1) it tends to make
testing worse as it decreases the mental
discipline, and 2) often enough such supposedly
testing code makes it into the real thing (or
bugs occur at the point when "OK, now it works,
let's just rename it right").

--
underground experts united
http://user.it.uu.se/~embe8573


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Obtaining a Lisp form from a file

Udyant Wig-2
In reply to this post by John Mastro
On 07/25/2017 11:01 PM, John Mastro wrote:
> (with-temp-buffer
>   (insert-file-contents file)
>   (read (current-buffer)))
>
> Hope that helps
>
>         John

That is much better.  Thanks a lot.

--
... while the ways of art are hard at the best, they will break you if
you go unsustained by belief in what you are trying to do.
                                -- Arthur Quiller-Couch


Loading...