From: ken manheimer <ken.manheimer@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: bizarre problem with minor mode defined using define-minor-mode
Date: Sun, 16 Jan 2011 01:15:33 -0500 [thread overview]
Message-ID: <AANLkTi=zuwQbvO=MtMeOb_Vzw2GK+7U=-o+ok0oDOi1S@mail.gmail.com> (raw)
In-Reply-To: <jwv1v4dv4ql.fsf-monnier+emacs@gnu.org>
On Sat, Jan 15, 2011 at 11:48 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> i agree that the code is painfully complicated. however, the fset
>> actually is effective and necessary to impose the minor-mode keymap
>> adjustments allout does.
>
> I really can't understand who it could be effective. My reading of the
> code tells me that function binding is never used.
(elisp)Format of Keymaps: "A symbol whose function definition is a
keymap is also a keymap."
minor-mode-map-alist entries of the form `(allout-mode .
allout-mode-map)' apparently tells the emacs key resolution facility
to look in the function value of the symbol in the cdr. that's why
the fset i do works.
>> in fact, removing the fset leads to the same problems with the
>> regular, defun'ed allout-mode that i have been seeing with the
>> byte-compiled define-minor-mode defined allout mode.
>
> That's what I would expect, since I think this fset is a no-op.
it's not a no-op! as i said before, removing the fset changed
behavior. as i describe above, there's an explanation.
>> the problem with switching to define-minor-mode is that
>> define-minor-mode apparently associates the mode name with the keymap
>> value, itself, on minor-mode-map-alist.
>
> That's because that's what you told it:
>
> :keymap <exp>
>
> says to use the value of <exp> as the keymap, so ":keymap
> allout-mode-map" says to use the value of the variable as the keymap.
> If you want to use a symbol, then you need to quote it.
alas, that's apparently not so:
(defvar example-mode-map (make-sparse-keymap))
=> example-mode-map
(define-key example-mode-map "\C-cv" 'emacs-version)
=> emacs-version
(assq 'example-mode minor-mode-map-alist)
=> nil
(define-minor-mode example-mode
"example-mode docstring."
:keymap 'example-mode-map
nil)
=> (keymap (3 keymap (118 . emacs-version)))
(assq 'example-mode minor-mode-map-alist)
=> (example-mode keymap (3 keymap (118 . emacs-version)))
(it's helpful to discover that just executing the define-minor-mode
establishes the keymap in minor-mode-map-alist. i didn't expect that.
actually activating the mode doesn't change the situation.)
> This said, you can modify a keymap after the fact: as long as you don't
> do a (setq allout-mode-map <newmap>), you can modify allout-mode-map on
> the fly and those changes will take effect immediately without having to
> use an indirection through the allout-mode-map symbol.
are you suggesting doing a rplacd on the minor-mode-map-alist cell? i
guess that's better than the fset approach, since for the latter, in
addition to doing the obscure fset, i also have to do surgery to
remove the keymap that define-minor-mode puts on minor-mode-map-alist
(whether i provide :keymap with a keymap or a symbol).
> Stefan
next prev parent reply other threads:[~2011-01-16 6:15 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 ` bizarre problem with minor mode defined using define-minor-mode ken manheimer
2011-01-11 21:42 ` Stefan Monnier
2011-01-16 1:06 ` ken manheimer
2011-01-16 4:48 ` Stefan Monnier
2011-01-16 6:15 ` ken manheimer [this message]
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='AANLkTi=zuwQbvO=MtMeOb_Vzw2GK+7U=-o+ok0oDOi1S@mail.gmail.com' \
--to=ken.manheimer@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).