From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.cc-mode.general,gmane.emacs.devel Subject: Re: Last use of defadvice in Emacs Date: Fri, 8 Apr 2022 17:10:54 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33750"; mail-complaints-to="usenet@ciao.gmane.io" Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: cc-mode-help-bounces@lists.sourceforge.net Fri Apr 08 19:11:42 2022 Return-path: Envelope-to: sf-cc-mode-help@m.gmane-mx.org Original-Received: from lists.sourceforge.net ([216.105.38.7]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ncs98-0008f4-Fj for sf-cc-mode-help@m.gmane-mx.org; Fri, 08 Apr 2022 19:11:42 +0200 Original-Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1ncs8v-0005mN-Sx; Fri, 08 Apr 2022 17:11:29 +0000 Original-Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ncs8v-0005mH-Fv for cc-mode-help@lists.sourceforge.net; Fri, 08 Apr 2022 17:11:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=From:In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=IctkxHoLTKbL7kb9GgI3hTi7qqqjetkpK5h2k7UgknQ=; b=VW+zm48lnWT33J+cxK3/ojjr+e 2Yok5mCftx2gOYIpHaueN9dj3n1IIAOEPCOegA/n6VQA2TJ7dtNkuo6RVesTYaG33ez+hg8wbm3AI SEgmaT33UbBvTf8ektI22mdSZlGDAAqJEOYAgOf+3prfTRNlxJFuCwT9LxTAZag7GkG8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject: Cc:To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=IctkxHoLTKbL7kb9GgI3hTi7qqqjetkpK5h2k7UgknQ=; b=CHwK6ZpF0opwVisrNYJ70IB3Lu 4XNFOGaaSlvIvlyCSwkg1cqzcZwFmhqX5w/6rP7Ja/s3IZ8nmmDzudlh9+FNvPoxH6nyYsBv8Dutq 1sxv1zRPHCGG/HwAJWqo/SDs1xUdXV3BawX8Uh6MGAM4GEy7AEnnIOPjT776IHeqd6dA=; Original-Received: from eggs.gnu.org ([209.51.188.92]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1ncs8t-009wxq-KQ for cc-mode-help@lists.sourceforge.net; Fri, 08 Apr 2022 17:11:28 +0000 Original-Received: from colin.muc.de ([193.149.48.1]:36658 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1ncs8m-0006oM-Dk for bug-cc-mode@gnu.org; Fri, 08 Apr 2022 13:11:21 -0400 Original-Received: (qmail 76394 invoked by uid 3782); 8 Apr 2022 17:10:54 -0000 Original-Received: from acm.muc.de (p4fe159b9.dip0.t-ipconnect.de [79.225.89.185]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 08 Apr 2022 19:10:54 +0200 Original-Received: (qmail 7945 invoked by uid 1000); 8 Apr 2022 17:10:54 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Headers-End: 1ncs8t-009wxq-KQ X-BeenThere: cc-mode-help@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Bug reports, feature requests, and general talk about CC Mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: cc-mode-help-bounces@lists.sourceforge.net Xref: news.gmane.io gmane.emacs.cc-mode.general:8302 gmane.emacs.devel:287975 Archived-At: Hello, Stefan. On Thu, Apr 07, 2022 at 14:37:14 -0400, Stefan Monnier wrote: > > I want more than to "perform the test" at compile time. I want a Lisp > > form that will check whether that variable is bound, and if so, not even > > compile the sub-form. Something like C's #ifndef preprocessor form. It > > would look something like > > (hash-if (not > > (boundp 'font-lock-extend-after-change-region-function)) > > (progn > > (defmacro c-advise-fl-for-region (function) .....) > > (c-advise-fl-for-region ....) > > .... > > )) > > .. Here the progn form would be neither evaluated nor compiled if that > > font-lock-... variable were boundp. We don't have this at the moment. > > Not that it's all that important in the current case, but it might be > > handy to have, perhaps, in other version dependent code. > The patch I send does obey the requirement that the `defadvice` will be > "neither evaluated nor compiled" if the variable exists at compile-time. That's different from, and less demanding than, the "challenge" I set, I think. It's not at all important to Emacs's health, but ..... > It is not a separate "hash-if", OTOH. We can define such a "hash-if", > as seen for example in the `url-http-ntlm` GNU ELPA package: > (defmacro url-http-ntlm--if-when-compile (cond &rest body) > (declare (debug t) (indent 1)) > (when (eval cond) > `(progn ,@body))) > ;; Remove authorization after redirect. > (url-http-ntlm--if-when-compile > (and (boundp 'emacs-major-version) > (< emacs-major-version 25)) > ... > ... Various code, including, incidentally, a `defadvice` ... > ...) Here, a piece of `byte-code' gets compiled for the url-http-ntlm--if-when-compile call. This is useless code without any useful function. (I've just tried it.) The action I asked for (or, at least, meant to ask for) was for _no_ code to get compiled when a condition was not met. I still believe this is not possible at the moment. But the C preprocessor can do it with #ifndef. One use for this could be writing unit tests in the same file.el as what they're testing. They would get compiled only for a test run. > Along similar lines, there's AUCTeX's `TeX--if-macro-fboundp`: > (defmacro TeX--if-macro-fboundp (name then &rest else) > "Execute THEN if macro NAME is bound and ELSE otherwise. > Essentially, > (TeX--if-macro-fboundp name then else...) > is equivalent to > (if (fboundp 'name) then else...) > but takes care of byte-compilation issues where the byte-code for > the latter could signal an error if it has been compiled with > emacs 24.1 and is then later run by emacs 24.5." > (declare (indent 2) (debug (symbolp form &rest form))) > (if (fboundp name) ;If macro exists at compile-time, just use it. > then > `(if (fboundp ',name) ;Else, check if it exists at run-time. > (eval ',then) ;If it does, then run the then code. > ,@else))) I haven't been able to find AUCTeX's source code yet, but I'm not sure this macro would meet the "no code at all" criterion, either. > No such macro has reached ELisp's core yet, probably because the > precise requirements tend to be subtly different (often depending on > the authors's own preferences about what they want to consider as > legitimate or important use-cases, as is the case in the cc-mode code: > what should happen when compiled on Emacs-NN but run on Emacs-MM?). > Stefan -- Alan Mackenzie (Nuremberg, Germany).