unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION
@ 2024-03-03 10:49 Adam Porter
  2024-03-03 11:18 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Porter @ 2024-03-03 10:49 UTC (permalink / raw)
  To: 69521

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>





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION
  2024-03-03 10:49 bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION Adam Porter
@ 2024-03-03 11:18 ` Eli Zaretskii
  2024-03-03 21:04   ` Adam Porter
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2024-03-03 11:18 UTC (permalink / raw)
  To: Adam Porter; +Cc: 69521

severity 69521 wishlist
thanks

> Date: Sun, 3 Mar 2024 04:49:02 -0600
> From: Adam Porter <adam@alphapapa.net>
> 
> 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:

Thanks, but I think this should be discussed on emacs-devel first.
The bug tracker is not a good vessel of discussing ideas; in
particular. quite a few of people who should be part of such a
discussion don't read bug-gnu-emacs regularly, and must be explicitly
CC'ed to take notice.

So I suggest to start the discussion on emacs-devel, and only switch
here if/when the idea and its implementation aspects are clear enough
to post a patch.

Thanks.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION
  2024-03-03 11:18 ` Eli Zaretskii
@ 2024-03-03 21:04   ` Adam Porter
  0 siblings, 0 replies; 3+ messages in thread
From: Adam Porter @ 2024-03-03 21:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 69521

On 3/3/24 05:18, Eli Zaretskii wrote:

> Thanks, but I think this should be discussed on emacs-devel first.
> The bug tracker is not a good vessel of discussing ideas; in
> particular. quite a few of people who should be part of such a
> discussion don't read bug-gnu-emacs regularly, and must be explicitly
> CC'ed to take notice.
> 
> So I suggest to start the discussion on emacs-devel, and only switch
> here if/when the idea and its implementation aspects are clear enough
> to post a patch.

Ok, I filed the bug report because I had mentioned it in that thread and 
it seemed to get overlooked.  Now I've posted a new thread.  Please see:

https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00118.html





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-03 21:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-03 10:49 bug#69521: 29.1; Adding a DECLARE spec equivalent to DECLARE-FUNCTION Adam Porter
2024-03-03 11:18 ` Eli Zaretskii
2024-03-03 21:04   ` Adam Porter

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).