2

When I do this (setq v (f-read-text "s.el")) where s.el is of this form

((thing1 . thing2) (thing3 . thing4))

I get v back as one long string. And (setq v (append (f-read-text "s.el"))) doesn't seem to change things to a list. I want to do a push or add-to-list an item, but I seem to be adding that item to a list containing a big string. I'd like to return the contents of s.el as a list and then do the push or add-to-list. Then I need to write it back out, again not as a string.

3
  • is (append (read v) '((thing5 . thing6))) what you're looking for?
    – mutbuerger
    Commented Dec 1, 2015 at 20:18
  • 2
    What is f-read-text ?
    – phils
    Commented Dec 1, 2015 at 20:24
  • Probably from f.el
    – npostavs
    Commented Dec 1, 2015 at 20:29

1 Answer 1

3

If your file contains just one lisp form, all you need to do is

(setq v (read (f-read-text "s.el")))

(see Input Functions).

If there are several forms, like (a b) (c d), you will need to read in cycle using read-from-string or do

(read (concat "(" my-string ")"))
1
  • After your (setq v (read (f-read-text "s.el"))) a (push '(thing5 . thing6) v) does exactly what I wanted. Thanks.
    – 147pm
    Commented Dec 2, 2015 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.