From: Stefan Monnier via CC-Mode-help <cc-mode-help@lists.sourceforge.net>
To: Alan Mackenzie <acm@muc.de>
Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org
Subject: Re: Last use of defadvice in Emacs
Date: Wed, 06 Apr 2022 17:08:21 -0400 [thread overview]
Message-ID: <jwvk0c26i69.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <Yk3hd38sQ3sq75Ar@ACM> (Alan Mackenzie's message of "Wed, 6 Apr 2022 18:52:39 +0000")
>> 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≥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).
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
-(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 ()
next prev parent reply other threads:[~2022-04-06 21:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 19:49 Last use of defadvice in Emacs Stefan Monnier
2022-04-04 20:08 ` T.V Raman
2022-04-04 20:38 ` Stefan Monnier via CC-Mode-help
2022-04-04 20:48 ` T.V Raman
2022-04-05 4:28 ` Richard Stallman
2022-04-06 18:52 ` Alan Mackenzie
2022-04-06 21:08 ` Stefan Monnier via CC-Mode-help [this message]
2022-04-07 1:51 ` T.V Raman
2022-04-07 2:49 ` Stefan Monnier via CC-Mode-help
2022-04-07 6:14 ` Eli Zaretskii
2022-04-07 21:59 ` Stefan Monnier via CC-Mode-help
2022-04-08 1:49 ` T.V Raman
2022-04-08 2:34 ` Stefan Monnier via CC-Mode-help
2022-04-08 14:21 ` T.V Raman
2022-04-08 6:00 ` Eli Zaretskii
2022-04-07 18:18 ` Alan Mackenzie
2022-04-07 18:37 ` Stefan Monnier
2022-04-08 17:10 ` Alan Mackenzie
2022-04-08 17:39 ` Stefan Monnier via CC-Mode-help
2022-04-08 18:06 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvk0c26i69.fsf-monnier+emacs@gnu.org \
--to=cc-mode-help@lists.sourceforge.net \
--cc=acm@muc.de \
--cc=bug-cc-mode@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).