From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ken manheimer Newsgroups: gmane.emacs.devel Subject: bizarre problem with minor mode defined using define-minor-mode Date: Sat, 25 Dec 2010 19:31:42 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0016e649847cd2235004984558d3 X-Trace: dough.gmane.org 1293323536 3523 80.91.229.12 (26 Dec 2010 00:32:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 26 Dec 2010 00:32:16 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 26 01:32:12 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PWeWw-0002bN-1y for ged-emacs-devel@m.gmane.org; Sun, 26 Dec 2010 01:32:10 +0100 Original-Received: from localhost ([127.0.0.1]:40709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PWeWv-0006jE-95 for ged-emacs-devel@m.gmane.org; Sat, 25 Dec 2010 19:32:09 -0500 Original-Received: from [140.186.70.92] (port=36092 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PWeWq-0006iz-1G for emacs-devel@gnu.org; Sat, 25 Dec 2010 19:32:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PWeWm-0007fZ-EK for emacs-devel@gnu.org; Sat, 25 Dec 2010 19:32:03 -0500 Original-Received: from mail-ww0-f49.google.com ([74.125.82.49]:41385) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PWeWm-0007fI-3S for emacs-devel@gnu.org; Sat, 25 Dec 2010 19:32:00 -0500 Original-Received: by wwb17 with SMTP id 17so7956116wwb.30 for ; Sat, 25 Dec 2010 16:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type; bh=X+n5oZ4HjZ6DcSxna/ZUPDK53k5cS3BRWWylRT2TP9s=; b=TzYZraAEs2Uks9+clpQHZjixK3o2BfaH+k9G7kkEMLpoBXZsbtY5QXTNxyGrzTi0q6 7r3Rv7nM8HA08G4ORIIGN+baVbzCOOZTvia8OAhy8sYTLKPlxerg6uVKgiXXufAd3qeE yATEEZnJgCwTdtLVws8rgVn66EcD7RkvQlATY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=G38K9UX9HQetRiK1rjGAfIeOEUOXJEDVMFyG6gQ5W9GkAFTciU+OP3rMCaha6vL7DZ 92iw1q3IOPeHbt4InJ571FxNDKEGdyZbGndz+izPBpG3U1XTONipsx/0d/hYOGREg0nn 1iFBarpAkSMqNOZ323NYNVgTJDgmnrX2VSlWQ= Original-Received: by 10.216.164.14 with SMTP id b14mr5988822wel.33.1293323517174; Sat, 25 Dec 2010 16:31:57 -0800 (PST) Original-Received: by 10.216.65.141 with HTTP; Sat, 25 Dec 2010 16:31:42 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133971 Archived-At: --0016e649847cd2235004984558d3 Content-Type: text/plain; charset=ISO-8859-1 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 --0016e649847cd2235004984558d3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable i'm encountering a serious problem with a function created using define= -minor-mode - and the problem is only occurring when operating with the byt= e-compiled version of the function. =A0i've tried to debug the problem,= but am stumped. =A0i'm able to reproduce the problem in a few versions= of emacs, though, and have created a bzr branch on launchpad with a copy o= f the code.

one of the final steps in my updates to allout.el is migrating allout-m= ode minor mode to `define-minor-mode'. =A0however, some key substitutio= ns way deep in my code do only happen properly when i use a explicitly eval= uated (via eval-defun or eval-when-compile) version of the define-minor-mod= e to define the allout-mode function. =A0if the minor mode was established = by a byte-compiled version of the function the same key substitutions do no= t show in the mode. =A0(there are some other keybinding problems that occur= , as well.)

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

the problem h= appens identically on the x toolkit and chiba-u versions of emacs, both run= ning on macox X snow leopard:

=A0GNU 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

=A0GNU Emacs 23.1.90.2 (x86_= 64-apple-darwin10.4.0, X toolkit) of 2010-11-05 on crisp

i can repro= duce the problem by wrapping the define-minor-mode in either `eval-and-comp= ile' or `eval-when-compile' and doing an `emacs-lisp-byte-compile-a= nd-load' to show the different behaviors. =A0i've created a bzr bra= nch on launchpad.net with a prepared v= ersion (details, below) of allout.el for others to try:

=A0=A0http://bazaar.laun= chpad.net/~ken-manheimer/emacs/alloutdev/annotate/head:/lisp/allout.el?star= t_revid=3D102483

in this version i've wrapped the define-minor-mode with eval-and-co= mpile. =A0that can be changed to test the different behaviors.

when = byte-compiling and loading with the eval-when-compile, invoking=A0the mode = yields the key substitutions, as it ought. =A0(of course, the=A0step of loa= ding the byte-compiled code is irrelevant at that point,=A0because the func= tion isn't in the byte-compiled code. =A0it's only=A0defined becaus= e it was evaluated during the byte-compile.) =A0 with the=A0eval-and-compil= e, loading the byte-compiled allout.elc wipes out the=A0key substitutions -= they're no longer in effect. =A0of course, the lack of the function in= the byte-compiled code when using eval-when-compile=A0makes the byte-compi= led code useless, so i have no workaround for the=A0problem, just a weird d= emonstration of it.

i've tried tracking down the failed key substitutions, by wrapping= =A0define-key with some advice that noted when the key defines happened,=A0= and they do every time the mode is activated, whether or not it's via= =A0the byte-compiled version of the mode function (when defined by=A0define= -minor-mode). =A0my function which does the key substitutions=A0(allout-set= up-mode-map) uses fset to ensure that the mode map is=A0properly globally e= stablished, so it's already kind of complicated. =A0i'm also wonder= ing whether i'm just misunderstanding something about=A0the way define-= minor-mode is supposed to work.

to see the problem, visit this version (see link, above) of allout.el= =A0and start allout-mode. =A0then emacs-lisp-byte-compile-and-load the=A0co= de, and you'll find that \C-a is bound to move-beginning-of-line, as=A0= it normally is - not replaced by allout-beginning-of-line, as it=A0should b= e.

then change the `eval-and-compile' that's wrapped around the=A0= define-minor-mode allout-mode to `eval-when-compile', do=A0emacs-lisp-b= yte-compile-and-load, and you'll find that \C-a is=A0properly bound to = allout-beginning-of-line. =A0(you can also just=A0manually evaluate the def= ine-minor-mode - that will also the=A0keysubsitutions in the keymap immedia= tely.)

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

--0016e649847cd2235004984558d3--