[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Keybindings and minor modes
From: |
batkins57 |
Subject: |
Re: Keybindings and minor modes |
Date: |
29 Dec 2005 14:02:13 -0800 |
User-agent: |
G2/0.2 |
Kevin Rodgers wrote:
> batkins57@gmail.com wrote:
> I'll admit, I don't understand the point of calling
> (self-insert-command 0).
self-insert-command requires an argument, so as a special case, I have
to call it with a 0; I can't simply do (funcall 'self-insert-commnand).
>
> Perhaps a better approach altogether would be to add a pre-command-hook
> that would check the key that was used to invoke it:
>
> (defun ehinter-pre-command-hook ()
> "Run `ehinter-hint' in Ehinter Minor Mode, when invoked via SPC, TAB,
> or RET."
> (when (and ehinter-mode
> (let ((key (this-single-command-keys)))
> (and (= (length key 1))
> (member (aref key 0) '(? ?\t ?\r))))) ; SPC, TAB,
> or RET
> (ehinter-hint)))
>
> (add-hook 'pre-command-hook 'ehinter-pre-command-hook)
>
> Then the ehinter-mode function just needs to set or unset the
> buffer-local ehinter-mode variable.
>
> You could tweak that to have the ehinter-mode function add or remove
> ehinter-pre-command-hook from the buffer-local pre-command-hook, to
> avoid affecting other buffers.
>
> --
> Kevin Rodgers
I got a neat solution from the folks on emacs-devel. Stefan Monnier
suggested the following:
(call-interactively (let ((ehinter-mode nil))
(key-binding
(this-command-keys))))
Bill