From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66908: Exposing more public nadvice API Date: Sat, 04 Nov 2023 04:13:51 -0400 Message-ID: References: <878r7fw802.fsf@posteo.net> <87msvufz8n.fsf@gmail.com> <875y2ifd2c.fsf@gmail.com> <87wmuydobs.fsf@gmail.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35045"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Philip Kaludercic , 66908@debbugs.gnu.org To: Visuwesh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 04 09:14:40 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qzBnj-0008z9-Vk for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Nov 2023 09:14:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzBnc-0003gh-8R; Sat, 04 Nov 2023 04:14:32 -0400 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 1qzBnV-0003g5-Rn for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:14:25 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzBnV-0001nf-Jn for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:14:25 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qzBo5-0007Ey-KW for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:15:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Nov 2023 08:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66908 X-GNU-PR-Package: emacs Original-Received: via spool by 66908-submit@debbugs.gnu.org id=B66908.169908567827787 (code B ref 66908); Sat, 04 Nov 2023 08:15:01 +0000 Original-Received: (at 66908) by debbugs.gnu.org; 4 Nov 2023 08:14:38 +0000 Original-Received: from localhost ([127.0.0.1]:60414 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzBnh-0007E7-I1 for submit@debbugs.gnu.org; Sat, 04 Nov 2023 04:14:37 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:59255) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzBne-0007Ds-Qf for 66908@debbugs.gnu.org; Sat, 04 Nov 2023 04:14:36 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 0DD548076B; Sat, 4 Nov 2023 04:13:53 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1699085632; bh=RBZeVhNHEe+4fGvpJ4h+sqzz+12x0YytrvsZFSSZuIw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=ezDXHWQZWj/p3U3eespxYhLz9+wsRNOYCUhYhYHIxqPyo9iPSH70NzFl7sdlHyFMX R92Baj6nwJ343MhVIsj1ZCXMZC5EM0f2AGMGpL9bfvI/boQEcQ2EPYjd8v6m4DInqn akNzHD6uLu1Gtb+ijbgz/oWGwGBbnth9Pqo6ZSiujO7LQPPRV3vQEJTauJvUaEUswf jp077/SvBfPDVjEZ5XTEm2DnsGPeA8ZUeffn3flUprZYBBOyydMWMbzw4RtK+85F4I YvB2JK/BtUmZcPPU6F/SMpqdYCSMK9iJA4KGWgNS1z0rXXHoPoT4gqin/UQ5Xj/hMu U/r9RZdmy39bg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 2310A80409; Sat, 4 Nov 2023 04:13:52 -0400 (EDT) Original-Received: from pastel (unknown [45.72.195.71]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id EAA651202FC; Sat, 4 Nov 2023 04:13:51 -0400 (EDT) In-Reply-To: <87wmuydobs.fsf@gmail.com> (Visuwesh's message of "Sat, 04 Nov 2023 11:58:39 +0530") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273750 Archived-At: > Sure, in Philip's package do-at-point, a function defined to "act" on > the `thing' at point are given different arguments depending on the > minimum number of arguments required by the function: Ah :-( So a kind of "unimplementable semantics" for DWIM purposes. > (pcase (car (func-arity func)) > ^^^^^^^^^^^^^^^^^ > (0 (funcall func)) > (1 (funcall func (buffer-substring (car bound) (cdr bound)))) > (2 (funcall func (car bound) (cdr bound))) > (_ (error "Unsupported signature: %S" func))))) I recommend: (condition-case nil (funcall func (car bound) (cdr bound)) (wrong-number-of-arguments (condition-case nil (funcall func (buffer-substring (car bound) (cdr bound))) (wrong-number-of-arguments (funcall func))))) :-) Works with advice and other wrappers without having to worry about `indirect-function`, autoloading, etc... >>> (func-arity (advice--cd*r (indirect-function 'xref-find-definitions= ))) ;; =E2=87=92 (1 . 1) >>> which is the right return value. It might be nice to not have to call >>> `indirect-function' here for the "global" function but you can be a >>> better judge of that. >> Don't know what you mean by "global" function. > By "global", I mean the new global function advice-cd*r or somesuch that > might eventually be added from this discussion. Ah, I see. I don't think `advice-cd*r` should follow aliases in general. But indeed, you may have an `advice` object whose `advice-cd*r` is a symbol, whose definition is another advice object, etc... Another good reason to prefer the `condition-case` approach :-) >> By "autoloaded" do you mean "setup to be loaded on demand but not yet >> loaded", or do you mean "had been setup to be loaded on demand and has >> been loaded already"? > The former obviously. In that case, `indirect-function` would not see the advice, then `func-arity` would cause the target to be (auto)loaded, during which a previously pending advice could be installed and it would return the dreaded (0 . many) from the advice it sees in the definition. Again, using `condition-case` side steps the issue. Stefan