emacs-devel
[Top][All Lists]
Advanced

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

`unreadablep'


From: Lars Ingebrigtsen
Subject: `unreadablep'
Date: Wed, 15 Dec 2021 08:49:58 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Do we have any primitive that can be used to check whether an object is
printable or not?  Code like this (from savehist.el) makes me believe
"not":

                ;; Print elements of VALUE one by one, carefully.
                (dolist (elt value)
                  (let ((start (point)))
                    (insert " ")
                    ;; Try to print and then to read an element.
                    (condition-case nil
                        (progn
                          (prin1 elt (current-buffer))
                          (save-excursion
                            (goto-char start)
                            (read (current-buffer))))
                      (error
                       ;; If writing or reading gave an error, comment it out.
                       (goto-char start)
                       (insert "\n")
                       (while (not (eobp))
                         (insert ";;; ")
                         (forward-line 1))
                       (insert "\n")))
                    (goto-char (point-max))))

It would be nice to have such a function (i.e., that says whether it can
be read back after printing it).  The problem is, of course, complex
structures that require recursing (and then checking for loops), etc, so
you basically have to implement it the way printing is done if you want
it to be fast, I think?

Does anybody have any thoughts on this issue?

I wonder whether this could be efficiently implemented by, say, having
some kind of special value for PRINTCHARFUN for prin1, but I haven't
looked at the code yet.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




reply via email to

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