From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Visuwesh Newsgroups: gmane.emacs.bugs Subject: bug#59379: 29.0.50; `define-advice' documentation needs improving Date: Sat, 19 Nov 2022 20:14:32 +0530 Message-ID: <8735afatrj.fsf@gmail.com> References: <877czrb0av.fsf@gmail.com> 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="3623"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 59379@debbugs.gnu.org, Stefan Monnier To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 19 15:45:27 2022 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 1owP5x-0000dv-KC for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Nov 2022 15:45:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1owP5e-0007DB-8g; Sat, 19 Nov 2022 09:45:06 -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 1owP5a-0007Ca-32 for bug-gnu-emacs@gnu.org; Sat, 19 Nov 2022 09:45:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1owP5Z-0000Cb-OD for bug-gnu-emacs@gnu.org; Sat, 19 Nov 2022 09:45:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1owP5Z-0007VD-Ic for bug-gnu-emacs@gnu.org; Sat, 19 Nov 2022 09:45:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 Nov 2022 14:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59379 X-GNU-PR-Package: emacs Original-Received: via spool by 59379-submit@debbugs.gnu.org id=B59379.166886908428804 (code B ref 59379); Sat, 19 Nov 2022 14:45:01 +0000 Original-Received: (at 59379) by debbugs.gnu.org; 19 Nov 2022 14:44:44 +0000 Original-Received: from localhost ([127.0.0.1]:39406 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owP5H-0007UW-Qs for submit@debbugs.gnu.org; Sat, 19 Nov 2022 09:44:44 -0500 Original-Received: from mail-pg1-f194.google.com ([209.85.215.194]:40790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owP5F-0007UI-Po for 59379@debbugs.gnu.org; Sat, 19 Nov 2022 09:44:42 -0500 Original-Received: by mail-pg1-f194.google.com with SMTP id f9so3210134pgf.7 for <59379@debbugs.gnu.org>; Sat, 19 Nov 2022 06:44:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2/w7YAf9gQNgCM5eZ/icOO+mTRBX5PD5Rcxs7MAdCZM=; b=nPkFZPVUd8DDNSNKpwkU9wZ9qqqna2HxiF+JssUw8hVU61aXiY7xaboIKqUpC5DdQk cEic2QDZfFNrPvbER6htut13/25a98kxgwRTWpDYbIQ2q4dxUYHSFGouyVfJJcB6cD8L UuzEvuzL22+qXUtpnML2RAjPKuZEdT3Lai1kQ7xvpH/z2nrLM2IMhIu+rRafLswUaSgi tHQTdsaktFvyiDIl2e/xsiZB2Eace97wLuWARpprVMBLgmgy8AgRkay4+u2M2K3q1wmr fRkGpg+FyEoKxRcVLe58q08LY5dr9EeL+p36tnSnl4vlmJQ7Q9jh6mgZvM46uUVPKmz+ hqSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2/w7YAf9gQNgCM5eZ/icOO+mTRBX5PD5Rcxs7MAdCZM=; b=amKNE2WbZ73SxK5Xom6rF0XVEwyozpuOBZN+DmZLcsSSlHnB+YdX51OaeTyHCPmsSQ 9d+iqd/jn/E52GJ8lcg03PNeAOzBFFFji53boQWlhSqZabBye93/uK2e2aMZtFm33fu2 ddRYIy1kX+5+rgJ/yMxmvovpFjwwAdcwNNVLokJcwsbAJYO5h50g3peBQHglpQ/hTWrj HhUWGyuagjB7bGtpYGhdHNFFd1S+Lqx4ISqcxcAA8Ad8+PpBdsvliuK766bMd1qUOLEA NcrxH7BmBo/QmElugAr4WsfgUlBH3GbZ5N5gic/f6/RjDQS1K3kx8N38MHWneb8Jh8Gl 8nog== X-Gm-Message-State: ANoB5pnQ7K1K15r1YKl/bTB3V45QXDGhGnZK7zLiRXSoRZF8xi4XxmHi XDFHdC6zxhrHkz6oKh6mLY8= X-Google-Smtp-Source: AA0mqf4osnQHCKPks7a8zpLTf4Ox945Mz4oZJxGifDKREFqCGyHF14TfwMyLSCW8bhCFxmql+UeOWw== X-Received: by 2002:aa7:824f:0:b0:56e:8ed7:569f with SMTP id e15-20020aa7824f000000b0056e8ed7569fmr12592686pfn.19.1668869075831; Sat, 19 Nov 2022 06:44:35 -0800 (PST) Original-Received: from localhost ([118.185.152.162]) by smtp.gmail.com with ESMTPSA id x23-20020aa79ad7000000b0056bcb102e7bsm5202131pfp.68.2022.11.19.06.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 06:44:35 -0800 (PST) In-Reply-To: (Stefan Kangas's message of "Sat, 19 Nov 2022 05:52:41 -0800") 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:248345 Archived-At: [=E0=AE=9A=E0=AE=A9=E0=AE=BF =E0=AE=A8=E0=AE=B5=E0=AE=AE=E0=AF=8D=E0=AE=AA= =E0=AE=B0=E0=AF=8D 19, 2022] Stefan Kangas wrote: > Visuwesh writes: > >>> 3. This is its argument list: >>> >>> (define-advice SYMBOL (HOW LAMBDA-LIST &optional NAME DEPTH) &rest >>> BODY) >>> >>> The HOW, LAMBDA-LIST, NAME, DEPTH parameters are not documented in >>> the docstring, nor in the info manual. >> >> HOW, LAMBDA-LIST, NAME, and DEPTH arguments become clear when once looks >> up the add-function docstring, and the docstring already mentions >> add-function. > > Then that should be explicitly stated. Is that not already spelt out? Define an advice and add it to function named SYMBOL. See =E2=80=98advice-add=E2=80=99 and =E2=80=98add-function=E2=80=99 for= explanation on the ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ arguments. Note if NAME is nil the advice is anonymous; ^^^^^^^^^^ otherwise it is named =E2=80=98SYMBOL@NAME=E2=80=99. > And LAMBDA-LIST is not explained there either, AFAICT. Reading the advice-add's document should tell what it means but I might be biased here. >>> 5. The documentation of NAME says that: "The advice is an anonymous >>> function if NAME is =E2=80=98nil=E2=80=99 or a function named =E2=80= =98symbol@name=E2=80=99." >>> >>> I struggle with parsing this sentence. It sounds like it is saying >>> that, if I want an anonymous function, I should define a function >>> named `symbol@name' (substituting `symbol' and `name') and then pass >>> that argument as the NAME argument? But then the function is not >>> anonymous? >> >> Would a comma help before the "or"? i.e., >> >> The advice is an anonymous function if NAME is =E2=80=98nil=E2=80=99= , or a function >> named =E2=80=98symbol@name=E2=80=99. > > So it can be either nil or a symbol? How do I actually use it? Yes. See below for an example with a non-nil NAME (define-advice file-cache-file-name (:filter-return (filename) vz/add-s= lash-if-directory) "Add a trailing slash if FILENAME is a directory." (if (file-directory-p filename) (concat filename "/") filename)) which creates a function file-cache-file-name@vz/add-slash-if-directory. But if NAME was nil, then there would be no named function but rather a lambda that gets added as an advice (which is hard to remove later). >> Changing symbol@name to SYMBOL@NAME like in the docstring will make it >> clearer, I think. If still not clear, the following happens in the case >> of NAME being nil vs. non-nil >> >> NAME nil =3D=3D> (advice-add SYMBOL HOW (lambda LAMBDA-LIST BODY) ..= .) >> NAME non-nil =3D=3D> (advice-add SYMBOL HOW (defun SYMBOL@NAME LAMBD= A-LIST BODY) ...) > > This all needs to be explained clearly in the documentation. Again, it seems obvious to me.