* doc/lispref/streams.texi (Input Functions): Document it.
* lisp/subr.el (readablep): New function (bug#52566).
non-@code{nil} value and does nothing except flushing pending output.
@end defun
+@defun readablep object
+This predicate says whether @var{object} can be written out and then
+read back by the Emacs Lisp reader. If it can't, this function
+returns @code{nil}, and if it can, a printed representation (via
+@code{prin1}) of @var{object} is returned.
+@end defun
+
@node Output Streams
@section Output Streams
@cindex stream (for printing)
\f
* Lisp Changes in Emacs 29.1
+** New function 'readablep'.
+This function says whether an object can be written out and then
+read back by the Emacs Lisp reader.
+
+++
** New variable 'print-unreadable-function'.
This variable allows changing how Emacs prints unreadable objects.
(push func chain))
chain))))
+(defun readablep (object)
+ "Say whether OBJECT has a readable syntax.
+This means that OBJECT can be printed out and then read back
+again by the Lisp reader. This function returns nil if OBJECT is
+unreadable, and the printed representation (from `prin1') of
+OBJECT if it is readable."
+ (declare (side-effect-free t))
+ (catch 'unreadable
+ (let ((print-unreadable-function
+ (lambda (_object _escape)
+ (throw 'unreadable nil))))
+ (prin1-to-string object))))
+
;;; subr.el ends here
(should (equal (function-alias-p 'subr-tests--d t)
'(subr-tests--e))))
+(ert-deftest test-readablep ()
+ (should (readablep "foo"))
+ (should-not (readablep (list (make-marker)))))
+
(provide 'subr-tests)
;;; subr-tests.el ends here