* How to get the function by the keymap?
@ 2012-11-10 16:09 Adam Jiang
2012-11-10 16:38 ` Eli Zaretskii
[not found] ` <CAM=K+ioz-5dDkJ6-75QpY7at5Yu-7Ewh=i+kKQ8ad84wjH2UXw@mail.gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Adam Jiang @ 2012-11-10 16:09 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 678 bytes --]
Hi,
I am working on a minor mode in which I want to remap [backspace] key to
different functions in different situation. The lisp code looks like
(defun smart-operator-backspace ()
(interactive)
(cond ((looking-back "hello"))
(save-excursion
(replace-regexp-in-string ".*hello" "" (match-string 1))))
(t
(delete-char 1))))
However, (delete-char) never works for me. The reason is another minor mode
remapped the backspace key to function 'autopair-backspace'. Then, I
realized that I need a method to fetch the function by given keymap and get
it called rather thant have hardcoded deletion executed.
How can I do that with elisp code?
/Adam
[-- Attachment #2: Type: text/html, Size: 782 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to get the function by the keymap?
2012-11-10 16:09 How to get the function by the keymap? Adam Jiang
@ 2012-11-10 16:38 ` Eli Zaretskii
[not found] ` <CAM=K+ioz-5dDkJ6-75QpY7at5Yu-7Ewh=i+kKQ8ad84wjH2UXw@mail.gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2012-11-10 16:38 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sun, 11 Nov 2012 01:09:02 +0900
> From: Adam Jiang <jiang.adam@gmail.com>
>
> (defun smart-operator-backspace ()
> (interactive)
> (cond ((looking-back "hello"))
> (save-excursion
> (replace-regexp-in-string ".*hello" "" (match-string 1))))
> (t
> (delete-char 1))))
>
>
> However, (delete-char) never works for me. The reason is another minor mode
> remapped the backspace key to function 'autopair-backspace'. Then, I
> realized that I need a method to fetch the function by given keymap and get
> it called rather thant have hardcoded deletion executed.
>
> How can I do that with elisp code?
I think you want lookup-key or local-key-binding.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to get the function by the keymap?
[not found] ` <CAM=K+ioz-5dDkJ6-75QpY7at5Yu-7Ewh=i+kKQ8ad84wjH2UXw@mail.gmail.com>
@ 2012-11-12 4:27 ` Adam Jiang
0 siblings, 0 replies; 3+ messages in thread
From: Adam Jiang @ 2012-11-12 4:27 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1337 bytes --]
2012/11/11 Le Wang <l26wang@gmail.com>
> On Sun, Nov 11, 2012 at 12:09 AM, Adam Jiang <jiang.adam@gmail.com> wrote:
> > However, (delete-char) never works for me. The reason is another minor
> mode
> > remapped the backspace key to function 'autopair-backspace'. Then, I
> > realized that I need a method to fetch the function by given keymap and
> get
> > it called rather thant have hardcoded deletion executed.
> >
> > How can I do that with elisp code?
>
> You don't want to dig through the keymaps yourself. Just take your
> minor-mode out of the lookup chain and use `key-binding'.
>
> This is what I do here:
>
> https://github.com/lewang/rebox2/blob/master/rebox2.el#L2363
>
The code works like a charm. Thank you, Le.
>
> The deeper problem is that I have a chain of 3 functions from
> different minor-modes all bound to backspace. They share the key
> happily, but Emacs lacks the mechanism to document this calling chain
> when I ask about <BACKSPACE> with C-h k. I described the need to
> solve this as a feature request
> http://lists.gnu.org/archive/html/help-gnu-emacs/2012-10/msg00465.html
> , but there wasn't much interest. :(
>
It seems this is a good idea. I'd like to help but I am pretty new to
elisp. I'll try to get some experience about the keybinding-chain thing
first.
Best regards,
/Adam
--
> Le
>
[-- Attachment #2: Type: text/html, Size: 2323 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-12 4:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-10 16:09 How to get the function by the keymap? Adam Jiang
2012-11-10 16:38 ` Eli Zaretskii
[not found] ` <CAM=K+ioz-5dDkJ6-75QpY7at5Yu-7Ewh=i+kKQ8ad84wjH2UXw@mail.gmail.com>
2012-11-12 4:27 ` Adam Jiang
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).