emacs-devel
[Top][All Lists]
Advanced

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

Re: Keybindings and minor modes


From: Stefan Monnier
Subject: Re: Keybindings and minor modes
Date: Thu, 29 Dec 2005 13:41:13 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> I'd like to bind a command to tab in a minor mode I'm writing, but I'd
> also like to preserve any command that might have been attached to that
> key before making my binding (such as indentation).  In other words,
> I'd like to add functionality to an existing keybinding without
> completely overwriting the binding.

> The solution I came up with was to simply store the currently bound
> command in a buffer-local variable whenever the minor mode is invoked.
> Then the keys are bound to functions that provide my additional
> functionality and then funcall the old bindings.  This works, but I
> wonder if there isn't a cleaner way to pass a keychord event on to the
> next handler.  The code I have now is pretty ugly, since a key bound to
> self-insert-command has to be handled separately so that
> self-insert-command will get an argument of 0.

There's no supported way to do just that.  Among the possible ways to do
something similar:

- (call-interactively
   (let ((my-minor-mode nil)) (key-binding (this-command-keys))))

- don't change the key-bindings.  Instead put advice on the commands.

- do neither.  Use a post/pre-command-hook instead (and check this-command
  or somesuch to decide whether you should do something or not).

- another one I still haven't actually seen used:

   [...]
   (add-hook 'pre-command-hook 'my-pch-reenable)
   (setq my-minor-mode nil)
   (setq unread-command-events
         (nconc (mapcar 'identity (this-command-keys))
                unread-command-events))
   [...]

   (defun my-pch-reenable ()
     (setq my-minor-mode t)
     (remove-hook 'pre-command-hook 'my-pch-reenable))

> I've attached my code below in case it's useful.

Your code seems to do something similar to what eldoc-mode does.
Have you looked at eldoc-mode?


        Stefan




reply via email to

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