emacs-pretest-bug
[Top][All Lists]
Advanced

[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 14:02:05 -0800

Thanks for your help. I guess I was ignorantly assuming that
define-minor-mode was a built-in function, like defun.

However, doing what you suggest and compiling in Emacs 20 still produces a
.elc file that cannot be used with Emacs 21. Since define-minor-mode is not
defined in Emacs 20, the compiled code contains only the code for Emacs 20.
When that .elc code is loaded in Emacs 21, this error results:

Debugger entered--Lisp error: (error "Recursive load"
"c:/drews-lisp-20/delsel.elc" "c:/drews-lisp-20/delsel.elc"
"c:/drews-lisp-20/delsel.elc" "c:/drews-lisp-20/delsel.elc"
"c:/drews-lisp-20/delsel.elc" "c:/drews-lisp-20/start.elc" "c:/_emacs")
  delete-selection-mode(t)
  byte-code("ACE#?...
  delete-selection-mode(t)
  byte-code("ACE#?...
  delete-selection-mode(t)
  byte-code("ACE#?...
  delete-selection-mode(t)
  byte-code("ACE#?...
  load("delsel")
  load-library("delsel")
  byte-code("...
  require(start)
  eval-buffer(#<buffer  *load*> nil "~/_emacs" nil t)
  ;;; Reading at buffer position 26902
  load-with-code-conversion("c:/_emacs" "~/_emacs" t t)
  load("~/_emacs" t t)
  #[nil "?...
  normal-top-level()

Is there a good way in this case to produce code that byte-compiles in Emacs
20 and runs in either Emacs 20 or Emacs 21?

FYI, here is the current code, to make sure I understood your prescription
correctly:

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

      ;; Emacs 21 ------------
      (define-minor-mode delete-selection-mode
        "Toggle Delete Selection mode.
With prefix ARG, turn Delete Selection mode on if and only if ARG is
positive.

When Delete Selection mode is enabled, Transient Mark mode is also
enabled and typed text replaces the selection if the selection is
active.  Otherwise, typed text is just inserted at point regardless of
any selection."
        :global t :group 'editing-basics
        (if (not delete-selection-mode)
            (remove-hook 'pre-command-hook 'delete-selection-pre-hook)
          (add-hook 'pre-command-hook 'delete-selection-pre-hook)
          (transient-mark-mode t))
        (when (interactive-p)
          (if (fboundp 'display-in-minibuffer) ; In `strings.el'.
              (display-in-minibuffer
               'event "Delete Selection mode is now "
               (list blue-foreground-face (if delete-selection-mode "ON"
"OFF")) ".")
            (message "Delete Selection mode is now %s."
                     (if delete-selection-mode "ON" "OFF")))))
    ;; Emacs 20 ---------------
    (defun delete-selection-mode (&optional arg)
      "Toggle Delete Selection mode.
When ON, typed text replaces the selection if the selection is active,
and DEL deletes the selection.  When OFF, typed text is inserted at
point, as usual. Enabling Delete Selection mode also enables Transient
Mark mode.

Non-nil prefix ARG turns mode on if ARG is positive, else turns it off."
      (interactive "P")
      (setq delete-selection-mode (if arg
                                      (> (prefix-numeric-value arg) 0)
                                    (not delete-selection-mode)))
      (force-mode-line-update)
      (if (not delete-selection-mode)
          (remove-hook 'pre-command-hook 'delete-selection-pre-hook)
        (add-hook 'pre-command-hook 'delete-selection-pre-hook)
        (transient-mark-mode t))
      (when (interactive-p)
        (if (fboundp 'display-in-minibuffer) ; In `strings.el'.
            (display-in-minibuffer
             'event "Delete Selection mode is now "
             (list blue-foreground-face (if delete-selection-mode "ON"
"OFF")) ".")
          (message "Delete Selection mode is now %s."
                   (if delete-selection-mode "ON" "OFF")))))))

Thanks,

  Drew

-----Original Message-----From: Stefan
> If the attached file is byte-compiled in Emacs 20 and the resulting .elc
> file is loaded in Emacs 21, then the error below results. If the same .elc
> is loaded in Emacs 20, there is no error. If the same source file is
> byte-compiled in Emacs 21 and the resulting file is loaded in Emacs 21,
then
> there is no error.

The code ha a bug: it does a runtime test to decide whether to avoid using
a macro or not.  The test should be done at compile time because once the
file is compiled, without the macro you can't run it with the macro.

I.e. the comparison with emacs-version should be wrapped inside
`eval-when-compile'.  Of course it should also be replaced with a test
like (fboundp 'define-minor-mode) (but still within `eval-when-compile').





reply via email to

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