From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.erc.general,gmane.emacs.devel Subject: Re: Copying autoloads Date: Tue, 26 Jul 2022 23:00:24 +0000 Message-ID: <87wnbzh43b.fsf@posteo.net> References: <87fsixw4co.fsf@neverwas.me> <87edyhrrw0.fsf@posteo.net> <871qugu3y3.fsf@neverwas.me> <87bktddnrs.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26937"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "J.P." , emacs-devel , Amin Bandali , emacs-erc@gnu.org To: Stefan Monnier Original-X-From: emacs-erc-bounces+sf-erc-help=m.gmane-mx.org@gnu.org Wed Jul 27 01:00:51 2022 Return-path: Envelope-to: sf-erc-help@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 1oGTXn-0006qe-7F for sf-erc-help@m.gmane-mx.org; Wed, 27 Jul 2022 01:00:51 +0200 Original-Received: from localhost ([::1]:55294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGTXl-0006QJ-L9 for sf-erc-help@m.gmane-mx.org; Tue, 26 Jul 2022 19:00:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGTXY-0006Q4-IZ for emacs-erc@gnu.org; Tue, 26 Jul 2022 19:00:36 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:43347) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGTXW-0004AS-9A for emacs-erc@gnu.org; Tue, 26 Jul 2022 19:00:36 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 9E2FB240027 for ; Wed, 27 Jul 2022 01:00:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1658876430; bh=scR/tpPTQYMpy/NAC0vScQLPPo1AFPb0IlHDKTFjwgA=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=rpbueL27nOqkNPvlA3/wcMZZx+2AMA7UQmqceEro1A7WTgDlDIxO1jmR3wd7dcg6z qJO95nK1SZ4HhljJDi5uaVGnHgfTO+Eip90rfGUWq63jfZc6qr4S/kZM0VX/rqXKPG MOtH8ObpIT5a82N3UwJ6O2tOPq6mIFFaax4eAzH9MDS+U7YLURnkqHccWnNB1iQE7s 4Psmu4WKn45rbT3EnLap4CLHNcoVjiXyovJ1OnVBInTWxrT0/Q1gNHWxRzSyktT6v/ tyEepTTLlfPqim4n8VllQb2CHaUKM9EVMrEVjK4xQxtXan6duSMUdcBhY2pVuT50iQ S8O0pQ02xOGog== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Lssnn4XV0z6tpb; Wed, 27 Jul 2022 01:00:29 +0200 (CEST) In-Reply-To: (Stefan Monnier's message of "Tue, 26 Jul 2022 17:00:40 -0400") Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-erc@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General discussion about ERC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-erc-bounces+sf-erc-help=m.gmane-mx.org@gnu.org Original-Sender: "emacs-erc" Xref: news.gmane.io gmane.emacs.erc.general:1889 gmane.emacs.devel:292721 Archived-At: Stefan Monnier writes: > Philip Kaludercic [2022-07-25 18:56:39] wrote: >> (defun get-compatibility-func (name) >> "Return the function NAME of a compatibility alias." >> (let* ((compat (intern-soft (format "compat-%s" name)))) >> (or (symbol-function (if (fboundp name) name compat)) >> (error "No definition for %S could be found" name)))) > > Side note: if `name` is autoloaded this will not return a "valid" value, > in the sense that the (autoload ...) value stored in `symbol-function` > is only usable when placed inside `name` and not elsewhere (e.g. you > can't `funcall` it, and if you store it in another symbol, calling the > function under that other symbol will probably fail). > > Autoloads are somewhat hackish in this sense. Would getting rid of the `symbol-function' simplify the issue? Here would be an updated proposal: --8<---------------cut here---------------start------------->8--- (defun get-compatibility-func (name &optional version) "Return the function NAME of a compatibility alias. If the optional argument VERSION is non-nil, it is interpreted as a string designating from what version on the actual function may be used, even if the function may have existed prior to that." ;; Compat is an ELPA package that provides compatibility code for ;; older versions of Emacs. To avoid overriding or advising ;; existing functionality, updates to existing functions are ;; provided by defining a "prefixed" function, starting with ;; `compat-'. The following code will attempt to return a symbol ;; designating NAME if it is defined (and allowed according to ;; VERSION), otherwise fall back to one provided by Compat. ;; ;; The assumption here is that either the user is tracking a recent ;; enough version of Emacs to have all the necessary definition, or ;; they are using a core package updated from ELPA, in which case ;; Compat has been added as a dependency. Otherwise an error is ;; signalled as early as possible. ;; ;; See https://elpa.gnu.org/packages/compat.html for more details. (let ((compat (intern-soft (format "compat-%s" name))) (func (symbol-function name))) (cond ((and (or (null version) (version<= version emacs-version)) (fboundp name)) name) ((fboundp compat) compat) ((error "No definition for %S could be found" name))))) --8<---------------cut here---------------end--------------->8--- The function could be added to compat.el too, so that any core package that depends on ELPA can make use of it.