From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: Adding a DECLARE spec equivalent to DECLARE-FUNCTION Date: Sun, 3 Mar 2024 13:17:21 -0600 Message-ID: <0156399d-eead-4855-8f40-8018e0efe331@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21975"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Mar 03 20:18:25 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rgrLs-0005TS-Eo for ged-emacs-devel@m.gmane-mx.org; Sun, 03 Mar 2024 20:18:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgrKz-0001Rv-AJ; Sun, 03 Mar 2024 14:17:29 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgrKx-0001Rm-Re for emacs-devel@gnu.org; Sun, 03 Mar 2024 14:17:27 -0500 Original-Received: from eastern.birch.relay.mailchannels.net ([23.83.209.55]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgrKv-0000ee-7z for emacs-devel@gnu.org; Sun, 03 Mar 2024 14:17:27 -0500 X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 157974C1032 for ; Sun, 3 Mar 2024 19:17:23 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a232.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 8FAFA4C1147 for ; Sun, 3 Mar 2024 19:17:22 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1709493442; a=rsa-sha256; cv=none; b=bJgyqLyGVE5f1X2vPiUpWhJ9dWoTVyBKaUCGMYDkFEPThuU4vcCzHVStw+RE5e18sqNKQQ bLgaoN8fSI53pXkRqQMPpkhqdFKx1GEKrpcfvlyR/oy67Sc9kdvpbOioP787nS8HfK/A3E X1MheZPHhzHyf8suOIb063MvtOzwAInHWTjwbsJp67dPe5NWZiu2Dcv9F5kMvE4Wby/4T/ 8wuBDt7/H8YeJT/m+NE0Xz3M8nazDiS5LrejTMBeGfOe224glEuUnXDY8Cd/4jBc7U+8nI w/Pj/UmasfhL9MjNqKw1kKC69pSN6X2/a1AZkNo99TPOpSl7/+6zYRnpfw4OoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1709493442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=yoSB8J2kdRChshH68iRT5fbpJh4cmeo+6DgMH9FWPA8=; b=RzdL4HaA2CtRb2LuMOtfpWL19b1Eac39Brr6n2U6Ghp0eNwAgUlUZ8jOZIeMXXrft4PSe2 SphxuKA3kECDUd0c46uNXbjCoV4bnfX3qOteG/QAUnr0I7NyDSfHSY71Wzw+RG5QzcKqvv eKYJZVCrV5ZiCyETqxUFNlEntWxwsZ/ZWPGP7KRl/6O8glj4X57G0lEXFkxWllEyluu/VS 2K8KjHOCBt1H0ZSaB3fGw8p7KJgglT3L0d6wWBod2+VCGKrn780eBY+3n0pNKFFbEmXsiC 8rHIQK6sv7S0Q0hRmHjZ22P4QwXJ24IzhefFPNF+ICGsS0NSLC1BUkSBb5gr9Q== ARC-Authentication-Results: i=1; rspamd-55b4bfd7cb-2hzk2; auth=pass smtp.auth=dreamhost smtp.mailfrom=adam@alphapapa.net X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|adam@alphapapa.net X-MailChannels-Auth-Id: dreamhost X-Imminent-Befitting: 6fe32f8b3fe53861_1709493442823_2424260198 X-MC-Loop-Signature: 1709493442823:3970845530 X-MC-Ingress-Time: 1709493442823 Original-Received: from pdx1-sub0-mail-a232.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.124.220.170 (trex/6.9.2); Sun, 03 Mar 2024 19:17:22 +0000 Original-Received: from [10.66.3.66] (unknown [91.193.232.98]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adam@alphapapa.net) by pdx1-sub0-mail-a232.dreamhost.com (Postfix) with ESMTPSA id 4Tns5t1qxQz2w for ; Sun, 3 Mar 2024 11:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alphapapa.net; s=dreamhost; t=1709493442; bh=yoSB8J2kdRChshH68iRT5fbpJh4cmeo+6DgMH9FWPA8=; h=Date:To:From:Subject:Content-Type:Content-Transfer-Encoding; b=VEuSMbo7YeKUBPm/XPN/e908Elic1bqrorz68QQp0PCt/oD12eOwdUWpwXq4R54jB e4yT8Kw0smT//LYYEX3EmVOk1qz2+04bz2HckHsTy0c9KEHChFeGQsnSiqXXQF3/nF COQU2Brb+wifWRhJa3RmuaDBCkaLcmpClg5uQVHVnrN9fQcLB1ZjG1LscXhrrMiFsN yXKyiqJiPteBpt/LNwZvo7a1IC9j97YKSLqdnGRTVFgwdkqIAr+gtGIwx4Y5T2TMoQ rfrGDrGPLB6l8ej6Gy2F80/cVD99KTXD0qMm40yg4NulKnSPkWPmELAPrZ9KZ57FV4 27pGvUu1AFHWA== Content-Language: en-US Received-SPF: neutral client-ip=23.83.209.55; envelope-from=adam@alphapapa.net; helo=eastern.birch.relay.mailchannels.net X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316769 Archived-At: [See .] 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] [Ement]