emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : Re: `unreadablep'


From: Drew Adams
Subject: RE: [External] : Re: `unreadablep'
Date: Wed, 15 Dec 2021 17:00:16 +0000

> I was thinking that for efficiency (and ease of usage),
> nothing would be printed.  That is, something like
> 
> (defun unreadablep (object)
>   (condition-case nil
>       (prin1 object 'error-on-unprintable)
>     (:success t)
>     (unprintable-error nil)))

FWIW, I've always used this.

(defun bmkp-readable-p (value)
  "Return non-nil if VALUE is Lisp-readable if printed using `prin1'."
  (cond ((numberp value))
        ((symbolp value))
        ((and (stringp value)           ; String with no text properties.
              (if (fboundp 'equal-including-properties) ; Emacs 22+.
                  (equal-including-properties value (substring-no-properties 
value))
                (and (null (text-properties-at 0 value))
                     (= 0 (next-property-change 0 value))))))
        (t (with-temp-buffer
             (condition-case nil
                 (let ((print-readably  t)
                       (print-level     nil)
                       (print-circle    bmkp-propertize-bookmark-names-flag)
                       (print-gensym    bmkp-propertize-bookmark-names-flag))
                   (prin1 value (current-buffer))
                   (read (point-min-marker))
                   t)
               (error nil))))))         ; Could not print and read back.

Yes, it tries to print and then read back.
It would be great to have something better.

[And yes, "readable" is better than "unreadable",
as most tests will be (when (readablep X) ...).]

reply via email to

[Prev in Thread] Current Thread [Next in Thread]