emacs-devel
[Top][All Lists]
Advanced

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

Last use of defadvice in Emacs


From: Stefan Monnier
Subject: Last use of defadvice in Emacs
Date: Mon, 04 Apr 2022 15:49:16 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

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

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.


        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)




reply via email to

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