emacs-pretest-bug
[Top][All Lists]
Advanced

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

iswitchb-mode and iswitchb-global-map


From: Drew Adams
Subject: iswitchb-mode and iswitchb-global-map
Date: Sun, 31 Dec 2006 18:00:23 -0800

I think these are both bugs, but you might not think so.
You might want to think them over, in any case.

1. Shouldn't `iswitchb-global-map' be renamed
`iswitchb-mode-map'?  Wouldn't that better follow the
minor-mode naming convention?

2. Shouldn't `iswitchb-global-map' be redefined anew each
time `iswitchb-mode' is turned on?  I say this because it
uses `substitute-key-definition'.  New global bindings for
the commands in question (e.g. `switch-to-buffer') will not
be taken into account, otherwise.

This has an impact in two ways: 1) If `switch-to-buffer' is
later bound globally to something different from `C-x b' (an
additional binding or a substituted binding), then that
binding won't be picked up when `iswitchb-mode' is
re-entered later.  2) If some other command is later bound
to `C-x b', even if `iswitch-mode' is re-entered later than
that, `iswitch-mode' will still co-opt `C-x b' (I think it
should not, in that case).

In one of my own libraries, the minor mode function,
`icicle-mode', unbinds the mode-map variable,
`icicle-mode-map', whenever the mode is turned off.
Whenever the mode is turned on, `icicle-mode' calls a
function that does the following.  Shouldn't `iswitchb-mode'
do something similar (because it too uses
`substitute-key-definition')?

a. Delete `icicle-mode's entry from `minor-mode-map-alist'
(if present from previously turning on the mode).

b. Define `icicle-mode-map' from scratch.  Like the code
that defines `iswitchb-global-map', this code uses
`substitute-key-definition' for `switch-to-buffer':

(substitute-key-definition
  'switch-to-buffer 'icicle-buffer
  icicle-mode-map (current-global-map))

c. Add the mode entry to `minor-mode-map-alist' (this is
thus done anew each time the mode is turned on).

In effect, this is all just a way to render the minor-mode
map definition dynamic.  Because the mode map is defined
using `substitute-key-definition', I want the bindings to
reflect the latest state of the global keymap.

I wish there were an easier way to do this.  I wish, for
instance, that you could just provide, as the cdr of an
entry to `minor-mode-map-alist', an expression to be evaled
to a keymap value, or perhaps a function that is called to
return a keymap value.

That's not possible today, IIUC: you must provide, as the
cdr, a literal keymap or a symbol whose symbol-function is a
keymap (the function cell is looked up; the function is not
called).  I'd like that expression to be evaled, or that
function to be called, whenever the mode is turned on.  If
that were not practical, it could be evaled/called each time
`minor-mode-map-alist' were consulted for a key lookup.  In
that case, the expression or function would then need to
determine if it needed to refresh the map (i.e. if the mode
was just entered).

BTW, something I don't understand, and don't see documented:

Does `define-minor-mode' somehow add an entry to
`minor-mode-map-alist'? Looking at the `iswitchb-mode' code,
I don't see where that is done there.  Yet the entry
(iswitchb-mode . iswitchb-global-map) is nevertheless
present in `minor-mode-map-alist'.  I'm wondering what code
put it there?  I looked at the `define-minor-mode' macro
definition too, but I didn't see anything that updated
`minor-mode-map-alist'.  It's a mystery to me.

I wonder if others are also confused about this and think,
like I was thinking, that a minor-mode definition must
itself push the mode entry onto `minor-mode-map-alist'.
Perhaps the doc should say something about this not being
necessary, because it happens automatically.  But how does
it happen?


In GNU Emacs 22.0.91.1 (i386-mingw-nt5.1.2600)
 of 2006-12-11 on LENNART-69DE564
X server distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (3.4) --cflags -Id:/g/include'





reply via email to

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