From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Last use of defadvice in Emacs Date: Mon, 04 Apr 2022 15:49:16 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20880"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: bug-cc-mode@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Apr 04 21:50:31 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbSic-0005Fo-FH for ged-emacs-devel@m.gmane-mx.org; Mon, 04 Apr 2022 21:50:30 +0200 Original-Received: from localhost ([::1]:49442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nbSia-0000p3-VN for ged-emacs-devel@m.gmane-mx.org; Mon, 04 Apr 2022 15:50:28 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbShb-0008UM-Or for emacs-devel@gnu.org; Mon, 04 Apr 2022 15:49:28 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbShX-0004rO-PW; Mon, 04 Apr 2022 15:49:26 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id E14BE806F8; Mon, 4 Apr 2022 15:49:19 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 251C18065C; Mon, 4 Apr 2022 15:49:18 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1649101758; bh=nqu9Alqt6KAJ4ZUi5IJxCfg7GJabXYeBysk3yU0aLS4=; h=From:To:Cc:Subject:Date:From; b=b1C8sYH7/YMTrhknGmhDoQSDX4RJAT6/xFZ+VD+ZbXAVxsYWqmm1/vcPzLQeoFBWl SEvmd0HUWbCvpwfRHWr5ke3OmxvjWaCI20cs8VkixKHpQt6U2iT00FNOgQhPj0YrU4 VZtzSYDpkm+drcBJNj2Gmqtp/pMtJcIrRniN1gGaWhqTbwNbXIrnXVi6rue02tO5oP qDfaVi27jY8xpfxPEEp/79bX8Bezi5T7oAwj2FVaccJkbRWyGSswAVHhU9RUMwJIwo p4XgFhdWdbh9ZvcHla1bt4q5bhYmk6rfm2PROQ4Bxvfia+5WghjXE2YcemWwI6kWEh VdEX7BBlwj29Q== Original-Received: from alfajor (unknown [45.72.221.51]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B06001201BE; Mon, 4 Apr 2022 15:49:17 -0400 (EDT) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:287772 Archived-At: 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)