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: Re: Last use of defadvice in Emacs Date: Thu, 07 Apr 2022 14:37:14 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30881"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 07 20:38:29 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 1ncX1Z-0007p9-Nb for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Apr 2022 20:38:29 +0200 Original-Received: from localhost ([::1]:60298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncX1Y-0007gj-6F for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Apr 2022 14:38:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncX0U-0006II-JJ for emacs-devel@gnu.org; Thu, 07 Apr 2022 14:37:22 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:18784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncX0R-0002DK-UP; Thu, 07 Apr 2022 14:37:21 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E0BCB4409AA; Thu, 7 Apr 2022 14:37:17 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 1ACBA440BFE; Thu, 7 Apr 2022 14:37:16 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1649356636; bh=Tc9vDnTBwM8G+SSC0QtY+2nGyTIWTB5xXhOzER2dkoM=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Qh8V0KL6Qn/gygD2yOkEPQI9Kghzc+JoCLV3xDA7LWrUw/JjndqS+ud7FZ6pGfesc zVzgbkXs+ljQoBgoFgi4WkGTw0KftuOVY9POy7YZAFkNuW63opLSDRikI349i1BWrk tLcIln2Q0LIcftRobN/4VmPP1RQAsJWdnDszQPTxQKzpJqb8dj4HKwmpWXmQuT8hIw mRZ4SbweKU7KoMKF61qMfNe1YLOXIcbmxtI9TS59SzMK06D0v0mCmnGdQEA2W+0E4Q EU3L4DEK8BKABeDC61sdQszXu30la/z1DxwheSdz5yBzgIuzPBHuw7JslS/4q6Jehp o94NL0WQ2YsCQ== Original-Received: from pastel (unknown [45.72.221.51]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E2EA51202AF; Thu, 7 Apr 2022 14:37:15 -0400 (EDT) In-Reply-To: (Alan Mackenzie's message of "Thu, 7 Apr 2022 18:18:04 +0000") 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:287902 Archived-At: > 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. The patch I send does obey the requirement that the `defadvice` will be "neither evaluated nor compiled" if the variable exists at compile-time. It is not a separate "hash-if", OTOH. We can define such a "hash-if", as seen for example in the `url-http-ntlm` GNU ELPA package: (defmacro url-http-ntlm--if-when-compile (cond &rest body) (declare (debug t) (indent 1)) (when (eval cond) `(progn ,@body))) ;; Remove authorization after redirect. (url-http-ntlm--if-when-compile (and (boundp 'emacs-major-version) (< emacs-major-version 25)) ... ... Various code, including, incidentally, a `defadvice` ... ...) Along similar lines, there's AUCTeX's `TeX--if-macro-fboundp`: (defmacro TeX--if-macro-fboundp (name then &rest else) "Execute THEN if macro NAME is bound and ELSE otherwise. Essentially, (TeX--if-macro-fboundp name then else...) is equivalent to (if (fboundp 'name) then else...) but takes care of byte-compilation issues where the byte-code for the latter could signal an error if it has been compiled with emacs 24.1 and is then later run by emacs 24.5." (declare (indent 2) (debug (symbolp form &rest form))) (if (fboundp name) ;If macro exists at compile-time, just use it. then `(if (fboundp ',name) ;Else, check if it exists at run-time. (eval ',then) ;If it does, then run the then code. ,@else))) No such macro has reached ELisp's core yet, probably because the precise requirements tend to be subtly different (often depending on the authors's own preferences about what they want to consider as legitimate or important use-cases, as is the case in the cc-mode code: what should happen when compiled on Emacs-NN but run on Emacs-MM?). Stefan