unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Last use of defadvice in Emacs
@ 2022-04-04 19:49 Stefan Monnier
  2022-04-04 20:08 ` T.V Raman
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Stefan Monnier @ 2022-04-04 19:49 UTC (permalink / raw)
  To: bug-cc-mode; +Cc: emacs-devel

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)




^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-04-08 18:06 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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