From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Alan Mackenzie <acm@muc.de>
Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org
Subject: Re: Last use of defadvice in Emacs
Date: Thu, 07 Apr 2022 14:37:14 -0400 [thread overview]
Message-ID: <jwvilrkrbo7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <Yk8q3ElTZCf5wcl+@ACM> (Alan Mackenzie's message of "Thu, 7 Apr 2022 18:18:04 +0000")
> 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
next prev parent reply other threads:[~2022-04-07 18:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvilrkrbo7.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=acm@muc.de \
--cc=bug-cc-mode@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).