emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Last use of defadvice in Emacs


From: Alan Mackenzie
Subject: Re: Last use of defadvice in Emacs
Date: Thu, 7 Apr 2022 18:18:04 +0000

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]