[Top][All Lists]

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

RE: byte compiler warnings for different Emacs versions

From: Drew Adams
Subject: RE: byte compiler warnings for different Emacs versions
Date: Thu, 11 Nov 2004 16:01:50 -0800

If I use a compile-time test and I compile on Emacs 20, then the only code
that shows up in the .elc is the Emacs 20 version of the definition. Running
the .elc on Emacs 21 then tries to run the Emacs 20 version, which is
inappropriate and can result in errors.

I offered this file as an example to look at wrt your statement that "If a
file byte-compiled on Emacs-20 doesn't run on Emacs-21 it's generally
considered as a bug (but not the other way around)."  Is this perhaps not
part of your "generally" case (I guess so).

Anyway, this is the case that I was discussing from the beginning: I would
like a _runtime_ (top-level) test in compiled code that will make the right
function definition based on the runtime Emacs major version.

I know that (if (< emacs-major-version 21) (define-key...)(define-key...))
works in this way - I can use a .elc that is compiled in Emacs 20 for both
Emacs 20 and Emacs 21: the appropriate key binding is used; it is presumably
chosen at runtime.

For example, if I do this (at top level), and byte-compile in Emacs 20, then
the define-key is done only in Emacs 21, not in Emacs 20:

(when (>= emacs-major-version 21)
  (define-key menu-bar-dired-operate-menu [touch]
    '(menu-item "Change Timestamp..." dired-do-touch
                :help "Change timestamp of marked files")))

I had the impression that this also worked for defun in place of define-key.
I now think I was perhaps mistaken about that (please confirm this). And
apparently the following does not work, in any case: (if (...)
(define-minor-mode...) (defun...)). You say that both defun and
define-minor-mode suffer similarly, and I guess you're right.

__So, how do I define things (besides keys) differently at runtime from a
compiled file, based on the runtime major version?__

BTW, defun is referred to in Emacs 20 (via C-h f defun) as a "built-in
function". That is why I referred to it that way. And define-key is referred
to in both versions as a "built-in function".



-----Original Message-----From: Stefan Monnier
> Thanks for your help. I guess I was ignorantly assuming that
> define-minor-mode was a built-in function, like defun.

It's got nothing to do with being built-in or not.  The issue is whether
it's a function or not.  Neither `defun' nor `define-minor-mode' are
functions (one is a macro, the other is a special form).  I.e. both would
suffer similarly (except that `defun' also exists in Emacs-20 so the
specific problem wouldn't show up).

> (eval-when-compile                      ; (`define-minor-mode' is a
>   (if (fboundp 'define-minor-mode)

This is not what I suggested.  Read carefully what I said: *the comparison*
should be wrapped in eval-when-compile, not the whole if expression.  I.e.:

  (if (eval-when-compile (fboundp 'define-minor-mode))

reply via email to

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