unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: ken manheimer <ken.manheimer@gmail.com>
To: emacs-devel@gnu.org
Subject: bizarre problem with minor mode defined using define-minor-mode
Date: Sat, 25 Dec 2010 19:31:42 -0500	[thread overview]
Message-ID: <AANLkTik31DQJhEEVXjVo7wuouhXCh_TxD1Wswg0gaW2=@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimiwTZA4UHpEPo83cFZK9r4VWkwesGcDo4GGVGu@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3840 bytes --]

i'm encountering a serious problem with a function created using
define-minor-mode - and the problem is only occurring when operating with
the byte-compiled version of the function.  i've tried to debug the problem,
but am stumped.  i'm able to reproduce the problem in a few versions of
emacs, though, and have created a bzr branch on launchpad with a copy of the
code.

one of the final steps in my updates to allout.el is migrating allout-mode
minor mode to `define-minor-mode'.  however, some key substitutions way deep
in my code do only happen properly when i use a explicitly evaluated (via
eval-defun or eval-when-compile) version of the define-minor-mode to define
the allout-mode function.  if the minor mode was established by a
byte-compiled version of the function the same key substitutions do not show
in the mode.  (there are some other keybinding problems that occur, as
well.)

i wonder whether i'm somehow misusing define-minor-mode in a dumb way, but
am entirely missing it if that's the case.

the problem happens identically on the x toolkit and chiba-u versions of
emacs, both running on macox X snow leopard:

 GNU Emacs 23.2.91.1 (x86_64-apple-darwin10.5.0, Carbon Version 1.6.0 AppKit
1038.35) of 2010-12-20 on crisp

 GNU Emacs 23.1.90.2 (x86_64-apple-darwin10.4.0, X toolkit) of 2010-11-05 on
crisp

i can 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' to show the different behaviors.  i've
created a bzr branch on launchpad.net with a prepared version (details,
below) of allout.el for others to try:


http://bazaar.launchpad.net/~ken-manheimer/emacs/alloutdev/annotate/head:/lisp/allout.el?start_revid=102483

in this version i've wrapped the define-minor-mode with eval-and-compile.
 that can be changed to test the different behaviors.

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.

to see the problem, visit this version (see link, above) 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.)

help would be much appreciated!
--
ken manheimer
http://myriadicity.net

[-- Attachment #2: Type: text/html, Size: 4263 bytes --]

       reply	other threads:[~2010-12-26  0:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AANLkTimx4fP1f9Cj3_3ErkWEqj7sxNgTXG_Yxz-zi0xV@mail.gmail.com>
     [not found] ` <AANLkTimf5w9-N=j7wLnb339xDD7PCGDf1f=H4EGoO1TJ@mail.gmail.com>
     [not found]   ` <AANLkTimiwTZA4UHpEPo83cFZK9r4VWkwesGcDo4GGVGu@mail.gmail.com>
2010-12-26  0:31     ` ken manheimer [this message]
2011-01-11 21:42       ` bizarre problem with minor mode defined using define-minor-mode Stefan Monnier
2011-01-16  1:06         ` ken manheimer
2011-01-16  4:48           ` Stefan Monnier
2011-01-16  6:15             ` ken manheimer
2011-01-16  6:46               ` Stefan Monnier
2011-01-16  8:55                 ` Andreas Schwab
2011-01-20 18:21                 ` ken manheimer

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='AANLkTik31DQJhEEVXjVo7wuouhXCh_TxD1Wswg0gaW2=@mail.gmail.com' \
    --to=ken.manheimer@gmail.com \
    --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).