[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: `unreadablep'
From: |
Steingold |
Subject: |
Re: `unreadablep' |
Date: |
Wed, 15 Dec 2021 10:32:05 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) |
> * 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.
> 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.
Yeah, we could create a "/dev/null"-type object and pass it to prin1.
However, this would still make the above approach better in most cases.
--
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2022
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://honestreporting.com https://iris.org.il https://ffii.org
DRM "access management" == prison "freedom management".
- Re: `unreadablep', (continued)
Re: `unreadablep', Stefan Monnier, 2021/12/15
Re: `unreadablep',
Steingold <=
Re: `unreadablep', Steingold, 2021/12/15
Re: `unreadablep', Philipp Stephani, 2021/12/15