emacs-devel
[Top][All Lists]
Advanced

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

Re: Why shouldn't we have a #if .... #else .... #endif construct in Emac


From: Alan Mackenzie
Subject: Re: Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp?
Date: Wed, 6 Sep 2023 09:56:34 +0000

Hello, Richard.

On Tue, Sep 05, 2023 at 20:58:38 -0400, Richard Stallman wrote:
> [[[ To any NSA and FBI agents reading my email: please consider    ]]]
> [[[ whether defending the US Constitution against all enemies,     ]]]
> [[[ foreign or domestic, requires you to follow Snowden's example. ]]]

>   > For example, in CC Mode there is a chunk of code looking like ....

>   >   (when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later.
>   >     (electric-indent-local-mode (if c-electric-flag 1 0)))

>   > , and there are quite a few instances like it.  Here, there is a comment
>   > about which versions are relevant, but that is somewhat unusual.  Note
>   > here that we would have to test both the major and minor version numbers
>   > to do this correctly.

>   > I intend to replace that code with

>   >   (static-if (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later.
>   >     (electric-indent-local-mode (if c-electric-flag 1 0)))

>   > ..  (hash-if has been renamed static-if.)  It would be more work to
>   > replace it with

>   >   (when (or (> emacs-major-version 24)
>   >             (and (= emacs-major-version 24)
>   >            (>= emacs-minor-version 4)))
>   >     (electric-indent-local-mode (if c-electric-flag 1 0)))

> If you want to have a conditional about version mumbers,
> I think that is the right way to write it.

Originally, I wasn't really thinking about version numbers being the
prime use case, but it was easy to use them as an example to get the
discussion going.

> Or, if you want to keep the condition about the availability of
> electric-indent-local-mode, how about keeping the code unchanged

>   >   (when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later.
>   >     (electric-indent-local-mode (if c-electric-flag 1 0)))

> and inform the byte compiler that (fboundp 'electric-indent-local-mode)
> can be optimized based on the Emacs version?  This way you won't need
> to change the source code, and we will get the ideal results.

I don't know how to do this.  Early on in the thread, Ulrich Müller
suggested using

    (when (eval-when-compile (fboundp 'electric-indent-local-mode))
       (electric-indent-local-mode (if c-electric-flag 1 0)))

, in which the conditional gets optimised away at compile time.  But
that's still a change in the source code.

>   > static-if is a completely ordinary macro which is 10 lines long
>   > (including doc string), and there's a new section in the elisp manual for
>   > it.

> I think the simplicity of the source code as it will be
> counts for more than the simplicity of a new macro
> which, with my approach, we don't need to add.

We must also take into account the additional complexity of the defmacro
and defun macros (etc.) and the byte compiler to handle the new special
case.  As I've already said, there are just 45 occurrences of
emacs-major-version in the Lisp sources.

> -- 
> Dr Richard Stallman (https://stallman.org)
> Chief GNUisance of the GNU Project (https://gnu.org)
> Founder, Free Software Foundation (https://fsf.org)
> Internet Hall-of-Famer (https://internethalloffame.org)

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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