all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org
Subject: Re: Last use of defadvice in Emacs
Date: Wed, 6 Apr 2022 18:52:39 +0000	[thread overview]
Message-ID: <Yk3hd38sQ3sq75Ar@ACM> (raw)
In-Reply-To: <jwvv8voab07.fsf-monnier+emacs@gnu.org>

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).



  parent reply	other threads:[~2022-04-06 18:52 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 [this message]
2022-04-06 21:08   ` Stefan Monnier via CC-Mode-help
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yk3hd38sQ3sq75Ar@ACM \
    --to=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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.