From: Adam Porter <adam@alphapapa.net>
To: 69521@debbugs.gnu.org
Subject: bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION
Date: Sun, 3 Mar 2024 04:49:02 -0600 [thread overview]
Message-ID: <b7ea82de-7c7b-48ad-8352-df35a56e0143@alphapapa.net> (raw)
Hi,
In light of [this thread], this seems like a good time to propose this
idea: to enhance the `declare' form with a `function' spec equivalent to
the top-level `declare-function' form. This allows keeping the
declaration inside the function that makes it necessary, which has a few
advantages:
1. It clearly indicates which function makes the declaration necessary
(i.e. which function contains calls to the function in another
library).
2. If the function is moved to another file, the declaration moves with
it.
3. If the function is removed, the declaration is removed with it.
4. It reduces the number of top-level forms.
Also, it seems like a natural fit, i.e. `declare-function' to `(declare
(function ...))'.
As an experiment, I implemented this in [Ement] about 10 months ago, and
I've neither seen nor heard of any problems with it. Here's the code
that implements it:
┌────
│ (eval-and-compile
│ (defun ement--byte-run--declare-function (_name _args &rest values)
│ "Return a `declare-function' form with VALUES.
│ Allows the use of a form like:
│
│ (declare (function FN FILE ...))
│
│ inside of a function definition, effectively keeping its
│ `declare-function' form inside the function definition, ensuring
│ that stray such forms don't remain if the function is removed."
│ `(declare-function ,@values))
│
│ (cl-pushnew '(function ement--byte-run--declare-function)
defun-declarations-alist :test #'equal)
│ (cl-pushnew '(function ement--byte-run--declare-function)
macro-declarations-alist :test #'equal))
└────
In use, it looks like this:
┌────
│ (defun ement-notifications--make (notification)
│ "Return an `ement-notification' struct for NOTIFICATION.
│ NOTIFICATION is an alist representing a notification returned
│ from the \"/notifications\" endpoint. The notification's event
│ is passed through `ement--make-event'."
│ (declare (function ement--make-event "ement"))
│ (pcase-let (((map room_id _actions _ts event read) notification))
│ (make-ement-notification :room-id room_id :readp read
│ :event (ement--make-event event))))
└────
Would this be an acceptable addition to Emacs Lisp? If so, I'd be glad
to prepare a patch.
Thanks, Adam
[this thread]
<https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00057.html>
[Ement] <https://elpa.gnu.org/packages/ement.html>
next reply other threads:[~2024-03-03 10:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 10:49 Adam Porter [this message]
2024-03-03 11:18 ` bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION Eli Zaretskii
2024-03-03 21:04 ` Adam Porter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b7ea82de-7c7b-48ad-8352-df35a56e0143@alphapapa.net \
--to=adam@alphapapa.net \
--cc=69521@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.