emacs-devel
[Top][All Lists]
Advanced

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

Re: `unreadablep'


From: Qiantan Hong
Subject: Re: `unreadablep'
Date: Wed, 15 Dec 2021 16:04:08 +0000

> On Dec 15, 2021, at 7:32 AM, Steingold <sds@gnu.org> wrote:
> 
>> * Lars Ingebrigtsen <ynefv@tahf.bet> [2021-12-15 08:49:58 +0100]:
>> 
>> 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 think the above code is _perfect_.
> Why would one want to know in advance if the object is printable readably?
> Only to decide how to print it, right?
> Then the optimal approach is to _try_ to print readably and then take an
> alternative/remedial action on failure.
> This will usually save a structure traversal.
print already traverse it once, read traverse it twice.
If print support it natively we save in the best case one
half of the work.



reply via email to

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