branch: externals/compat commit f8ac79f1e0a007ed9dcc77f017359b8a376e07cf Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
compat-29: Add readablep --- NEWS.org | 1 + compat-29.el | 9 +++++++++ compat-tests.el | 6 ++++++ compat.texi | 10 ++++++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/NEWS.org b/NEWS.org index ee51da768f..ade97c75a9 100644 --- a/NEWS.org +++ b/NEWS.org @@ -26,6 +26,7 @@ - compat-29: Add ~get-scratch-buffer-create~. - compat-29: Add ~substitute-quotes~. - compat-29: Add ~read-multiple-choice~ with LONG-FORM argument. +- compat-29: Add ~readablep~. * Release of "Compat" Version 29.1.2.0 diff --git a/compat-29.el b/compat-29.el index df39dc6214..6c85933f7e 100644 --- a/compat-29.el +++ b/compat-29.el @@ -171,6 +171,15 @@ This function does not move point. Also see `line-end-position'." ;;;; Defined in subr.el +(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 error-free)) + (ignore-errors (equal object (read (prin1-to-string object))))) + (compat-defun buffer-local-restore-state (states) ;; <compat-tests:buffer-local-set-state> "Restore values of buffer-local variables recorded in STATES. STATES should be an object returned by `buffer-local-set-state'." diff --git a/compat-tests.el b/compat-tests.el index 7aad543243..5b217f6da2 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -2797,5 +2797,11 @@ (should-equal (substitute-quotes "'") "'") (should-equal (substitute-quotes "\\`") "\\`"))) +(ert-deftest readablep () + (should (readablep "foo")) + (should (readablep '("foo" 1 2.3 (a . b) [x y z] :key))) + (should-not (readablep (list (make-marker)))) + (should-not (readablep (make-marker)))) + (provide 'compat-tests) ;;; compat-tests.el ends here diff --git a/compat.texi b/compat.texi index 4a92e6a9c0..da33097d39 100644 --- a/compat.texi +++ b/compat.texi @@ -2101,6 +2101,14 @@ older than 29.1. Note that due to upstream changes, it might happen that there will be the need for changes, so use these functions with care. +@c copied from lispref/streams.texi +@defun readablep object +This predicate says whether @var{object} has @dfn{readable syntax}, +i.e., it can be written out and then read back by the Emacs Lisp +reader. If it can't, this function returns @code{nil}; if it can, +this function returns a printed representation (via @code{prin1}). +@end defun + @c copied from lispref/help.texi @defun substitute-quotes string This function works like @code{substitute-command-keys}, but only @@ -2834,8 +2842,6 @@ The function @code{count-sentences}. @item The command @code{string-edit} and @code{read-string-from-buffer}. @item -The function @code{readablep}. -@item The macro @code{with-undo-amalgamate}. @item The macro @code{with-delayed-message} and the function