From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Campbell Barton Newsgroups: gmane.emacs.devel Subject: Interest in temporary with-advice functionality? Date: Tue, 18 Jun 2024 14:12:53 +1000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6317"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 18 06:13:43 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 1sJQE2-0001MS-U8 for ged-emacs-devel@m.gmane-mx.org; Tue, 18 Jun 2024 06:13:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJQDQ-0002Ob-Ba; Tue, 18 Jun 2024 00:13:04 -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 1sJQDN-0002O8-Ll for emacs-devel@gnu.org; Tue, 18 Jun 2024 00:13:01 -0400 Original-Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJQDL-0003ZN-Uo for emacs-devel@gnu.org; Tue, 18 Jun 2024 00:13:01 -0400 Original-Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7041e39a5beso3666111b3a.3 for ; Mon, 17 Jun 2024 21:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718683978; x=1719288778; darn=gnu.org; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=/pyEbV1/9WyyNbZtilmEMe+7TdDAn0Dr81/w/LTSgVA=; b=U3OlYEt1MN9OqhFxu8L2JbKCWfJaREeV+z1e4DAeslIj/Q4y1/xaklOjK6gESEIkcA aRPYeWY1SDFfwdCQ/wDRdQ9VPMdlcU8PSXkYMVi11U9L8lX0o2pETz/53w3qZ2lmF9/K rW3NNiCeoMbxfeGFh0dZuldzTeWb44mr5soAEGnw9l94Y3A/FcjEOk/xemeM8ujuU5EW qgFCJFZ1wroQ9fU4nny6v/vNsCvEB6Fc++Dtx2L5P1m0K5hdSgLLmMPBUMwAO0zLy+WV gphPqYQzTXII85DYImPnqLB17lcmMfxpmzDuAItGpPxnkwLIZgA4/+2QfKM2YczXPVWg ODVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718683978; x=1719288778; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=/pyEbV1/9WyyNbZtilmEMe+7TdDAn0Dr81/w/LTSgVA=; b=l3jPRSin5ulB0fEhoS1u9NvqzPlMt12y5bxVGuaGR4StqqnjtdnkXOYFaDTvSi0ZwJ gm3CTfRJLVOACi035saCZeZlYYLnZF6gBxvlbUBjbILjSosO+BocWPginlsJjg7tvJiz h5uQ7bD1WXqugDjod7Jkvy9fjigFGli7rBJcj3nq6lnWf9O67CM9syTCmTZVn8RRKbgL Jetjt/8gmnvzNQ/yuJgG7AeSJl+nRwof78kHzkbcIdc0fI8Mmnsa62eCdpr2piF8nmUF nyzi5sdkMkyuwy101NjMKj1crtltmPJqqVuWJLr2fY0D7NTjmkmh6zdeXrx36aM/UuR6 wi5g== X-Gm-Message-State: AOJu0YwvZJmHzoOe/h7Q0w0JNlg3PwmMGReW3ly0OToDRueu1fVhHXUo +EVRfiHbg66vy7VBkc0ZNkoXrtVceitswcP6ASCuH58gek/zdKC3aAzwkQ== X-Google-Smtp-Source: AGHT+IG1/gaLucKYaHoGstRw4/LiTXFNH1vHOL6PrPqKZfKklZk7yqLn8lPciJEztO2qRGxzcHzleA== X-Received: by 2002:a05:6a00:bf5:b0:704:209a:c59e with SMTP id d2e1a72fcca58-705d7105202mr9598932b3a.9.1718683977699; Mon, 17 Jun 2024 21:12:57 -0700 (PDT) Original-Received: from ?IPV6:2402:b801:2c65:4b00::1? ([2402:b801:2c65:4b00::1]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6fedf49d7b1sm7354204a12.51.2024.06.17.21.12.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Jun 2024 21:12:57 -0700 (PDT) Content-Language: en-US Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=ideasman42@gmail.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-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:320226 Archived-At: Hi, for the various packages I maintain I've found it's sometimes useful to add temporary advice to a function and I was wondering if there is any interest to add a macro that supports temporary advice into emacs. While `cl-letf` can be used, advice is especially useful for it's :around functionality, while possible, it gets fairly verbose to use cl-letf to override the function in a way that supports calling the original. I've been using a "with-advice" macro (see [0]). The macros temporarily adds, then removed the advice (with-advice (('fn :around #'fn-override)) ;; Run's code with fn override. ... ) Multiple functions can be overridden at once. (with-advice (('fn :around #'fn-override) ('fn-another :after #'fn-after)) ;; Run's code with fn & fn-another override. ... ) I've noticed a similar macro exists in emacs but it's only used for testing. files-tests--with-advice in ./emacs/test/lisp/files-tests.el I was wondering if there is any interest to have this added to emacs. If so I could make a patch to support this. Since it can be useful to give concrete examples, here is some example usage [1] .. [4] (it's used 18 times across 9 packages I maintain). [0]: https://codeberg.org/ideasman42/emacs-recomplete/src/commit/7a5c4c86cdbf8ba6b045d5ace466e5dcb2f10db0/recomplete.el#L74 [1]: https://codeberg.org/ideasman42/emacs-elisp-autofmt/src/commit/98edd8158b778ff9a0e34b5c6615523c0035f8d6/elisp-autofmt.el#L442 [2]: https://codeberg.org/ideasman42/emacs-undo-fu/src/commit/ea902716f39c725db1b90dbb285b44404b3bd6df/undo-fu.el#L164 [3]: https://codeberg.org/ideasman42/emacs-recomplete/src/commit/7a5c4c86cdbf8ba6b045d5ace466e5dcb2f10db0/recomplete.el#L240 [4]: https://codeberg.org/ideasman42/emacs-doc-show-inline/src/commit/cc363ed39f023642c4d8e7c91b26c802ca356fa3/doc-show-inline.el#L530 Regards, - Campbell