From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "T.V Raman" Newsgroups: gmane.emacs.devel Subject: Re: Last use of defadvice in Emacs Date: Wed, 06 Apr 2022 18:51:27 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=gb18030 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10355"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Alan Mackenzie , 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 03:52:20 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 1ncHJs-0002UL-94 for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Apr 2022 03:52:20 +0200 Original-Received: from localhost ([::1]:59936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncHJq-0001gN-Q8 for ged-emacs-devel@m.gmane-mx.org; Wed, 06 Apr 2022 21:52:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncHJ9-0000v1-2t for emacs-devel@gnu.org; Wed, 06 Apr 2022 21:51:35 -0400 Original-Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:41873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncHJ7-0005D4-Ce for emacs-devel@gnu.org; Wed, 06 Apr 2022 21:51:34 -0400 Original-Received: by mail-pj1-x102c.google.com with SMTP id e8-20020a17090a118800b001cb13402ea2so253995pja.0 for ; Wed, 06 Apr 2022 18:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=BcM1e+/YTiZEwNZifvd7D0Y2nVnpoqqoTBU0haraWpQ=; b=lXsT9XqeoQihLC0Cgf2437u/JIZggrhO84OmjBchvrHSzKfu12yhEbnm1AlyTgOS+9 ANvcP7/DqNelZjDFB+DOD3qo6B4HztEYg2p5MUBKtbfzNa2Ykj7kG9yTziiLGGbwCBty ixohRSUNA13Yr5uqZi70oRzwXbJYbSJ4qSZH2qXjq1kjRSmxAkfjN3Wdp5/2S2bMtY3G +3YUwcEqiSAlMbSSycilKsqhaKPtZI1DaLxeTkOofr6FXK5a0him/VwCznpm72AP8SuX Z4/vnQr1VvZHc8alzOayC31K4nvuBmNU7AWg0Ii9d5QcUD6YMDJTOKIHxMmV38QCHS8s V4tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=BcM1e+/YTiZEwNZifvd7D0Y2nVnpoqqoTBU0haraWpQ=; b=xKwFe/Drcx3CqGwYLl0CqJ95f/fSi+Rlqb6V51apHoNHg/m8tFyREsPsRB72a2MkKs GG36GUqX0WZGaSexrG6hkiBmeRKLnLUToRJ2EEuB9RYyz2y6pM65Z2jImssM+dAYs54Q LAeSOP50UR7PikAFDeqf6P0tqBLKG285X5n9K77QaNYlWwJ0SJTjk0uoBwwuc8uPJF7V kMdlfmqyGwCh2N66YurB4fRo+DWSF1LdonqNFFIvE7H2RtIM1dfCsEaqwoAg3EawHgkb HLmILEuqOtu3HUeGX0o8G5EDyLf8RjR68dVSzt7pcm+ZgL7ZlpynfPEjVuoHOmE29vPh ofnQ== X-Gm-Message-State: AOAM530BWfyKD22KgOjf8Xa2ekiR62LdleN6ov5IihRLbFhyW5T7dMmo jJ7WRYGfzKk8oaSShjmvA9/3ZppoXQe6gQ== X-Google-Smtp-Source: ABdhPJxVCGW6W22x4Zn8aUzSbDn6wJBH3oGi391ICu/q12rRgP/VAZxrdJ0qYQyo+Uk1kX4AbXg1CQ== X-Received: by 2002:a17:903:2c5:b0:14f:4a29:1f64 with SMTP id s5-20020a17090302c500b0014f4a291f64mr11430817plk.90.1649296290971; Wed, 06 Apr 2022 18:51:30 -0700 (PDT) Original-Received: from raman-glaptop (c-24-4-174-65.hsd1.ca.comcast.net. [24.4.174.65]) by smtp.gmail.com with ESMTPSA id u18-20020a056a00125200b004fb112ee9b7sm18508852pfi.75.2022.04.06.18.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 18:51:30 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Wed, 06 Apr 2022 17:08:21 -0400") Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=raman@google.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -175 X-Spam_score: -17.6 X-Spam_bar: ----------------- X-Spam_report: (-17.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 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:287868 Archived-At: Stefan Monnier writes: Hi Stefan, Could you give some tips on what=20=20 issues one might see with defadvice and it's disrespect of lexical bindings? For the record, I switched emacspeak to lexical binding a couple of years ago and fixed any/all bytecomp warnings it generated --- and I've not hit any bugs to date. But it would be helpful to understand the types of issues defadvice might cause with lexical binding if something inexplicable does show up. This next is likely not lexical binding related, but the only issue I needed to create an emacspeak specific check was for the equivalent of (called-interactively 'interactive) which exhibited strange behavior with defadvice -- I created a "tighter" check that is emacspeak-specific. >>> 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. > >> 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=A1=DD22 (and also so code compiled on Emacs-28 w= ould > still activate the advice when run on some hypothetical future Emacs > where `font-lock-extend-after-change-region-function` has been removed). > > If you want to perform the test at compile time then I think something > like the following should work. > > > 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 >=20=20 > -(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) >=20=20 > ;; Connect up to `electric-indent-mode' (Emacs 24.4 and later). > (defun c-electric-indent-mode-hook () > > --=20 Thanks, --Raman(I Search, I Find, I Misplace, I Research) =817=A94 Id: kg:/m/0285kf1 =950=DC8