unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Lars Ingebrigtsen <larsi@gnus.org>, Po Lu <luangruo@yahoo.com>
Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: RE: [External] : Re: `unreadablep'
Date: Wed, 15 Dec 2021 17:00:16 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488C32259BD3E2145DCBFDFF3769@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <87wnk6l0yu.fsf@gnus.org>

> 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) ...).]

  parent reply	other threads:[~2021-12-15 17:00 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15  7:49 `unreadablep' Lars Ingebrigtsen
2021-12-15  8:19 ` `unreadablep' Po Lu
2021-12-15  8:35   ` `unreadablep' Lars Ingebrigtsen
2021-12-15  9:42     ` `unreadablep' Po Lu
2021-12-15 11:16       ` `unreadablep' Lars Ingebrigtsen
2021-12-15 11:25         ` `unreadablep' Po Lu
2021-12-15 12:19           ` `unreadablep' Lars Ingebrigtsen
2021-12-15 12:22             ` `unreadablep' Po Lu
2021-12-15 12:35               ` `unreadablep' Lars Ingebrigtsen
2021-12-15 12:42                 ` `unreadablep' Po Lu
2021-12-15 12:44                   ` `unreadablep' Lars Ingebrigtsen
2021-12-15 12:46                     ` `unreadablep' Po Lu
2021-12-15 12:51                       ` `unreadablep' Po Lu
2021-12-15 12:58                       ` `unreadablep' Lars Ingebrigtsen
2021-12-15 12:36               ` `unreadablep' Ihor Radchenko
2021-12-15 12:37                 ` `unreadablep' Po Lu
2021-12-15 17:00     ` Drew Adams [this message]
2021-12-15  8:35 ` `unreadablep' Ihor Radchenko
2021-12-15  9:51   ` `unreadablep' Po Lu
2021-12-15 10:20     ` `unreadablep' Ihor Radchenko
2021-12-15 10:21       ` `unreadablep' Ihor Radchenko
2021-12-15 10:21       ` `unreadablep' Po Lu
2021-12-15 10:36         ` `unreadablep' Ihor Radchenko
2021-12-15 10:44           ` `unreadablep' Po Lu
2021-12-15 11:12             ` `unreadablep' Ihor Radchenko
2021-12-15 11:16               ` `unreadablep' Po Lu
2021-12-15 11:39                 ` `unreadablep' Ihor Radchenko
2021-12-15 14:12 ` `unreadablep' Stefan Monnier
2021-12-16  5:48   ` `unreadablep' Lars Ingebrigtsen
2021-12-16  8:03     ` `unreadablep' Eli Zaretskii
2021-12-17  7:18       ` `unreadablep' Lars Ingebrigtsen
2021-12-16 15:35     ` `unreadablep' Qiantan Hong
2021-12-17  7:19       ` `unreadablep' Lars Ingebrigtsen
2021-12-15 15:32 ` `unreadablep' Steingold
2021-12-15 16:04   ` `unreadablep' Qiantan Hong
2021-12-15 16:09 ` `unreadablep' Steingold
2021-12-15 20:21 ` `unreadablep' Philipp Stephani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SJ0PR10MB5488C32259BD3E2145DCBFDFF3769@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=luangruo@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).