branches with status:
Name Status Last Modified Last Commit
lp:~ken-manheimer/emacs/alloutdev 1 Development 2010-12-25 23:55:35 UTC
102483. wrap define-minor-mode allout-mode in...

Author: ken manheimer
Revision Date: 2010-12-25 23:34:19 UTC

wrap define-minor-mode allout-mode in eval-and-compile, to help demonstrate
this problem:

serious problem with byte-compiled function created by define-minor-mode:

    i'm extremely perplexed, and blocked, by a problem i'm encountering in
    the process of migrating allout-mode minor mode (allout.el) to
    `define-minor-mode'. some key substitutions way deep in my code do not
    happen if the minor mode was established by a byte-compiled version of
    the function, but do happen if the mode definition is explicitly
    evaluated.

    i can even reproduce the problem by wrapping the define-minor-mode in
    either `eval-and-compile' or `eval-when-compile' and doing an
    `emacs-lisp-byte-compile-and-load'. when byte-compiling and loading
    with the eval-when-compile, invoking the mode yields the key
    substitutions, as it ought. (of course, the step of loading the
    byte-compiled code is irrelevant at that point, because the function
    isn't in the byte-compiled code. it's only defined because it was
    evaluated during the byte-compile.) with the eval-and-compile, loading
    the byte-compiled allout.elc wipes out the key substitutions - they're
    no longer in effect. of course, the lack of the function in the
    byte-compiled code when using eval-when-compile makes the byte-compiled
    code useless, so i have no workaround for the problem, just a weird
    demonstration of it.

    i've tried tracking down the failed key substitutions, by wrapping
    define-key with some advice that noted when the key defines happened,
    and they do every time the mode is activated, whether or not it's via
    the byte-compiled version of the mode function (when defined by
    define-minor-mode). my function which does the key substitutions
    (allout-setup-mode-map) uses fset to ensure that the mode map is
    properly globally established, so it's already kind of complicated.
    i'm also wondering whether i'm just misunderstanding something about
    the way define-minor-mode is supposed to work.

    i would love some help with this - migrating to define-minor-mode is
    one of the last things in my allout-mode update, but i've spent way
    too much time just tracking down the problem, and am more than
    reluctant to try to unravel the interaction between the byte-compiler
    and modes defined with define-minor-mode! but i'm completely blocked
    by this problem.

    to see the problem, visit this version of allout.el and start
    allout-mode. then emacs-lisp-byte-compile-and-load the code, and
    you'll find that \C-a is bound to move-beginning-of-line, as it
    normally is - not replaced by allout-beginning-of-line, as it should
    be.

    then change the `eval-and-compile' that's wrapped around the
    define-minor-mode allout-mode to `eval-when-compile', do
    emacs-lisp-byte-compile-and-load, and you'll find that \C-a is
    properly bound to allout-beginning-of-line. (you can also just
    manually evaluate the define-minor-mode - that will also the
    keysubsitutions in the keymap immediately.)

11 of 1 result