emacs-devel
[Top][All Lists]
Advanced

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

Re: Has eval-and-compile changed in emacs 27?


From: Basil L. Contovounesios
Subject: Re: Has eval-and-compile changed in emacs 27?
Date: Thu, 25 Feb 2021 15:30:17 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> eval-and-compile doesn't make sure the function is known at run time,
>> it only makes sure it is known at compile time.
>
> That's `eval-when-compile', surely...  `eval-and-compile' also evaluates
> at load time.

Yes, but non-top-level requires don't usually make functions known at
run time; for that one needs autoload/declare-function.

Here's how I'd write this particular code, for example:

  (autoload 'json-encode "json")

  (defun
    ...
    (if (not json)
        (pp table (current-buffer))
      (defvar json-encoding-pretty-print)
      (let ((json-encoding-pretty-print t))
        (insert (json-encode table))))
    ...)

or alternatively:

  (defun
    ...
    (if (not json)
        (pp table (current-buffer))
      (require 'json)
      (defvar json-encoding-pretty-print)
      (declare-function json-encode "json" (object))
      (let ((json-encoding-pretty-print t))
        (insert (json-encode table))))
    ...

-- 
Basil



reply via email to

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