6

I'm writing a lispy documentation engine with elisp and to make things easier, I'm trying to modify the following behavior

(prin1-to-string '(cons 'a 'b))
;; => "(cons (quote a) (quote b))"

to be

(prin1-to-string '(cons 'a 'b))
;; => "(cons 'a 'b)"

Is it possible to instruct prin1-to-string to reinstate reader macros like this? Reading through the C sources, I don't think it's possible since by the time the object has been read, we've already used the reader-macro to turn 'a into (quote a) and that ' is lost forever. Is my only hope regex-replace?

6

Just bind print-quoted to a non-nil value around the call to prin1(-to-string).

1
  • 1
    Wow, thanks! Looks like this behavior is defined in print.c:print_object's Lisp_Cons case. That function is getting too big :) Mar 6 '17 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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