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: Wed, 6 Apr 2022 18:52:39 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2985"; 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 Wed Apr 06 20:54:00 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 1ncAn1-0000W5-Qh for ged-emacs-devel@m.gmane-mx.org; Wed, 06 Apr 2022 20:53:59 +0200 Original-Received: from localhost ([::1]:55446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncAn0-0002FY-8J for ged-emacs-devel@m.gmane-mx.org; Wed, 06 Apr 2022 14:53:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncAm0-0001Ub-7e for emacs-devel@gnu.org; Wed, 06 Apr 2022 14:52:56 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:51245 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1ncAlx-0003We-It for emacs-devel@gnu.org; Wed, 06 Apr 2022 14:52:55 -0400 Original-Received: (qmail 85228 invoked by uid 3782); 6 Apr 2022 18:52:39 -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; Wed, 06 Apr 2022 20:52:39 +0200 Original-Received: (qmail 8959 invoked by uid 1000); 6 Apr 2022 18:52:39 -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-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:287856 Archived-At: Hello, Stefan. On Mon, Apr 04, 2022 at 15:49:16 -0400, Stefan Monnier wrote: > Hi Alan, > 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? > It's guaranteed 100% untested, tho. :-) > It's kinda weird in that this `defadvice` is not actually used in > current Emacsen, but we still have to macro-expand it, so the new code > macroexpands to the corresponding use of `advice-add` even tho that also > won't be used. Yes, Emacs 21 was a long time ago. Even CC Mode doesn't support it any more. The only thing which still uses the advice is XEmacs, and I don't thing that has advice-add. So I'm not sure the patch in the current form makes much sense. It might be better just to remove the < Emacs 22 bit altogether from the Emacs version of CC Mode. 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. > Stefan > diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el > index 957a0b8a7c5..759a01f1dd8 100644 > --- a/lisp/progmodes/cc-mode.el > +++ b/lisp/progmodes/cc-mode.el > @@ -2563,14 +2563,18 @@ c-extend-after-change-region > (cons c-new-BEG c-new-END)) > ;; Emacs < 22 and XEmacs > +(defun c--fl-extend-region (args) > + ;; Make sure that any string/regexp is completely font-locked. > + (if (not c-buffer-is-cc-mode) > + args > + (list c-new-BEG c-new-END (cddr args)))) > + > (defmacro c-advise-fl-for-region (function) > (declare (debug t)) > - `(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 > + (if (fboundp 'advice-add) > + `(advice-add ',function :filter-args #'c--fl-extend-region) > + `(defadvice ,function (before get-awk-region activate) > + (ad-set-args 0 (c--fl-extend-region (ad-get-args 0)))))) > (unless (boundp 'font-lock-extend-after-change-region-function) > (c-advise-fl-for-region font-lock-after-change-function) -- Alan Mackenzie (Nuremberg, Germany).