emacs-devel
[Top][All Lists]
Advanced

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

Re: `unreadablep'


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

Po Lu <luangruo@yahoo.com> writes:

> Yes, now I think the `print-unreadable-function' solution would be best;
> we could just cause a non-local exit from within that function.

The PRINTCHARFUN just gets a single character at a time, doesn't it?  So
it's not at the correct level to determine whether something is
unreadable or not...

I wonder whether two new simple read-* variables would cover all the use
cases (without having to go through prin1 twice ever).

1) When you want to signal an error, but use the representation
otherwise:

(use-thing
  (let ((print-error-on-unreadable t))
    (condition-case nil
       (prin1-to-string object)
      (unreadable-error (user-error "can't use this")))))

This would signal an error as soon as prin1 sees something unprintable,
so it'd be fast.

2) When you always want to insert it, but tweak it (a la savehist):

(let ((print-return-readable t)
      (start (point)))
  (unless (prin1 object (current-buffer))
    (goto-char start)
    (insert ";; ")))

I think that should cover the use cases?

Perhaps this is over engineering, but it would be nice to implement
things like this efficiently.

-- 
(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]