Add new function 'readablep'
* doc/lispref/streams.texi (Input Functions): Document it. * lisp/subr.el (readablep): New function (bug#52566).
This commit is contained in:
parent
e4d2a7894b
commit
f047d3c513
4 changed files with 28 additions and 0 deletions
|
@ -358,6 +358,13 @@ mode for @var{stream}. On POSIX hosts, it always returns a
|
|||
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)
|
||||
|
|
4
etc/NEWS
4
etc/NEWS
|
@ -977,6 +977,10 @@ functions.
|
|||
|
||||
* 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.
|
||||
|
|
13
lisp/subr.el
13
lisp/subr.el
|
@ -6561,4 +6561,17 @@ signalled. If NOERROR, the non-loop parts of the chain is returned."
|
|||
(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
|
||||
|
|
|
@ -1024,5 +1024,9 @@ final or penultimate step during initialization."))
|
|||
(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
|
||||
|
|
Loading…
Add table
Reference in a new issue