I was trying to read and eval Lisp forms from a string using a loop, instead of just putting the string into a buffer and using
eval-buffer to load everything in the string. That method was mentioned in another thread here.
The problem is that
read-from-string signals an error "End of file reached during parsing" and aborts my loop. I was hoping it would return nil, or some indication of the number of characters left, or give me some other way to figure out when to end my loop.
(while (< pos (length contents)) (setq pair (read-from-string contents pos)) (setq obj (car pair)) (setq pos (cdr pair)) .. inspect the read obj here .. maybe eval it, or toss it, or fix it.. )
Read-from-string returns starting position for the next read operation in the cdr of the pair returned. So I'm thinking that's so I can use it to start the next read in the right place. But I can't find any examples of how to read a string without getting the EOF error.
Probably it's just that I don't know how handle EOF errors while reading strings. Is there an ideomatic way of handling this kind of situation? Maybe with an
unwind-protect or something?