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.devel Subject: Re: Last use of defadvice in Emacs Date: Thu, 7 Apr 2022 18:18:04 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14347"; mail-complaints-to="usenet@ciao.gmane.io" Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 07 20:19:34 2022 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 1ncWjF-0003by-K7 for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Apr 2022 20:19:33 +0200 Original-Received: from localhost ([::1]:52074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncWjE-0000u4-1J for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Apr 2022 14:19:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncWhu-00004q-8F for emacs-devel@gnu.org; Thu, 07 Apr 2022 14:18:10 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:50786 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1ncWhr-0007GJ-Sk for emacs-devel@gnu.org; Thu, 07 Apr 2022 14:18:09 -0400 Original-Received: (qmail 93483 invoked by uid 3782); 7 Apr 2022 18:18:05 -0000 Original-Received: from acm.muc.de (p4fe15880.dip0.t-ipconnect.de [79.225.88.128]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 07 Apr 2022 20:18:04 +0200 Original-Received: (qmail 9571 invoked by uid 1000); 7 Apr 2022 18:18:04 -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=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" Xref: news.gmane.io gmane.emacs.devel:287899 Archived-At: Hello, Stefan. On Wed, Apr 06, 2022 at 17:08:21 -0400, Stefan Monnier wrote: > >> The patch below replaces the last remaining use of `defadvice` in Emacs > >> (well, except for Org where this has already been fixed upstream but > >> we're waiting for the change to trickle down to `master`). > > Why would we want to replace defadvice with advice-add? > > Don't all the objections to advice apply equally to both forms? > Both should be avoided, indeed. But `defadvice` is slowly being > replaced because it cannot obey `lexical-binding` (along with a bunch > of more minor annoyances) so it gets a few more objections. Ah, OK. > > I've spent an hour trying various combinations of eval-when-compile and > > (boundp 'font-lock-extend-after-change-region-function), to try and get > > the stuff compiled or ignored based on the presence/absence of that > > variable. Something like C's #ifdef. I didn't manage it, and don't > > think it's possible. That's another C facility Emacs Lisp seems to be > > missing. > I thought the code was written specifically to perform the test at > runtime, so that the code compiled on Emacs-21 would still skip the > advice when run on Emacsā‰„22 (and also so code compiled on Emacs-28 would > still activate the advice when run on some hypothetical future Emacs > where `font-lock-extend-after-change-region-function` has been removed). Maybe it was. It's such a long time ago, I can't remember. > If you want to perform the test at compile time then I think something > like the following should work. 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. > Stefan > diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el > index 957a0b8a7c5..05da61dbb2f 100644 > --- a/lisp/progmodes/cc-mode.el > +++ b/lisp/progmodes/cc-mode.el > @@ -2565,18 +2565,18 @@ > ;; Emacs < 22 and XEmacs > (defmacro c-advise-fl-for-region (function) > (declare (debug t)) > + (unless (boundp 'font-lock-extend-after-change-region-function) > `(defadvice ,function (before get-awk-region activate) > ;; Make sure that any string/regexp is completely font-locked. > (when c-buffer-is-cc-mode > (save-excursion > (ad-set-arg 1 c-new-END) ; end > - (ad-set-arg 0 c-new-BEG))))) ; beg > + (ad-set-arg 0 c-new-BEG)))))) ; beg > -(unless (boundp 'font-lock-extend-after-change-region-function) > - (c-advise-fl-for-region font-lock-after-change-function) > - (c-advise-fl-for-region jit-lock-after-change) > - (c-advise-fl-for-region lazy-lock-defer-rest-after-change) > - (c-advise-fl-for-region lazy-lock-defer-line-after-change)) > +(c-advise-fl-for-region font-lock-after-change-function) > +(c-advise-fl-for-region jit-lock-after-change) > +(c-advise-fl-for-region lazy-lock-defer-rest-after-change) > +(c-advise-fl-for-region lazy-lock-defer-line-after-change) > ;; Connect up to `electric-indent-mode' (Emacs 24.4 and later). > (defun c-electric-indent-mode-hook () -- Alan Mackenzie (Nuremberg, Germany).