emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bizarre problem with minor mode defined using define-minor-mode


From: ken manheimer
Subject: Re: bizarre problem with minor mode defined using define-minor-mode
Date: Sun, 16 Jan 2011 01:15:33 -0500

On Sat, Jan 15, 2011 at 11:48 PM, Stefan Monnier
<address@hidden> 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



reply via email to

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