all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Rebind key and save/reuse previous bound function
@ 2015-10-30  4:45 Joe Riel
  2015-10-30  4:57 ` Joe Riel
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Joe Riel @ 2015-10-30  4:45 UTC (permalink / raw)
  To: Help GNU Emacs

Is there a clean way save the function bound to a key
so that a new function can be created that is bound
to the same key, does something, then executes the
original bound function?   


-- 
Joe Riel




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Rebind key and save/reuse previous bound function
  2015-10-30  4:45 Rebind key and save/reuse previous bound function Joe Riel
@ 2015-10-30  4:57 ` Joe Riel
  2015-10-31 16:33   ` Emanuel Berg
  2015-10-30  4:58 ` Joe Riel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Joe Riel @ 2015-10-30  4:57 UTC (permalink / raw)
  To: Joe Riel; +Cc: Help GNU Emacs

On Thu, 29 Oct 2015 21:45:51 -0700
Joe Riel <joer@san.rr.com> wrote:

> Is there a clean way save the function bound to a key
> so that a new function can be created that is bound
> to the same key, does something, then executes the
> original bound function?   

key-binding will do what I described, and is probably what
theyI'll use, but what I think I really want
is something more akin to substitute-key-definition, but
which, rather than substituting a function, returns the
original function.  Does that exist?


-- 
Joe Riel




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Rebind key and save/reuse previous bound function
  2015-10-30  4:45 Rebind key and save/reuse previous bound function Joe Riel
  2015-10-30  4:57 ` Joe Riel
@ 2015-10-30  4:58 ` Joe Riel
  2015-10-30 18:31 ` Doug Lewan
  2015-10-31 20:22 ` John Mastro
  3 siblings, 0 replies; 8+ messages in thread
From: Joe Riel @ 2015-10-30  4:58 UTC (permalink / raw)
  To: Joe Riel; +Cc: Help GNU Emacs

On Thu, 29 Oct 2015 21:45:51 -0700
Joe Riel <joer@san.rr.com> wrote:

> Is there a clean way save the function bound to a key
> so that a new function can be created that is bound
> to the same key, does something, then executes the
> original bound function?   


The function key-binding will do what I described, and is probably
what I'll use, but what I think I really want is something more akin
to substitute-key-definition, but which, rather than substituting a
function, returns the original function.  Does that exist?


-- 
Joe Riel




^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Rebind key and save/reuse previous bound function
  2015-10-30  4:45 Rebind key and save/reuse previous bound function Joe Riel
  2015-10-30  4:57 ` Joe Riel
  2015-10-30  4:58 ` Joe Riel
@ 2015-10-30 18:31 ` Doug Lewan
  2015-10-31 20:22 ` John Mastro
  3 siblings, 0 replies; 8+ messages in thread
From: Doug Lewan @ 2015-10-30 18:31 UTC (permalink / raw)
  To: Joe Riel, Help GNU Emacs

That sounds like 'advice' to me. 
Try  info "(elisp) Advising Functions"  for details.
It begins with the following text that sounds like what you want
    The "advice" feature lets you add 
    to the existing definition of a function,....
-- 
,Doug
Douglas Lewan
Shubert Ticketing
(201) 994-4335

Nonfirstorderizability. It's a thing.


> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
> Behalf Of Joe Riel
> Sent: Friday, 2015 October 30 00:46
> To: Help GNU Emacs
> Subject: Rebind key and save/reuse previous bound function
> 
> Is there a clean way save the function bound to a key
> so that a new function can be created that is bound
> to the same key, does something, then executes the
> original bound function?
> 
> 
> --
> Joe Riel
> 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Rebind key and save/reuse previous bound function
  2015-10-30  4:57 ` Joe Riel
@ 2015-10-31 16:33   ` Emanuel Berg
  0 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2015-10-31 16:33 UTC (permalink / raw)
  To: help-gnu-emacs

Joe Riel <joer@san.rr.com> writes:

> The function key-binding will do what I described,
> and is probably what I'll use, but what I think
> I really want is something more akin to
> substitute-key-definition, but which, rather than
> substituting a function, returns the original
> function. Does that exist?

Instead of verbalizing this in half-baked terms of
techno-techno-technology, it'll be much easier for you
and us to understand and help if you just say what you
want to *do*.

I.e.:

    1. You are looking at Emacs.

    2. Your fingertips are at keys a, s, d, f
       and j, k, l, ;

    3. Your shoulders are relaxed (OK now, sorry :)

    4. What is it at this moment that you want to
       *do*, that you cannot?

Of course, feel free to speculate how to solve the
problem. Even if the theorizing is wrong it is still
better than doing nothing and if you put it into words
that will benefit the thought process and you will
look up information in doing so, *and* people won't
hesitate to tell you if you are wrong, which is
helpful to you and everyone else reading the post.

But before you do any of that, please do answer
question 4 or else the good intentions/activity will
much rather come to nothing.

And the beat goes on...  ((d[-_-]b))

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Rebind key and save/reuse previous bound function
  2015-10-30  4:45 Rebind key and save/reuse previous bound function Joe Riel
                   ` (2 preceding siblings ...)
  2015-10-30 18:31 ` Doug Lewan
@ 2015-10-31 20:22 ` John Mastro
  2015-11-01 22:08   ` Joe Riel
  3 siblings, 1 reply; 8+ messages in thread
From: John Mastro @ 2015-10-31 20:22 UTC (permalink / raw)
  To: Help GNU Emacs

Joe Riel <joer@san.rr.com> wrote:
>
> Is there a clean way save the function bound to a key
> so that a new function can be created that is bound
> to the same key, does something, then executes the
> original bound function?

I don't think there's anything built-in that does exactly what you
describe, but there are a few alternatives for doing it and all are
pretty simple.

Something like this would probably be the most direct translation of
your description:

    (defun define-before (map key cmd)
      (let ((old (lookup-key map key)))
        (define-key map key
          (if (null old)
              cmd
            (lambda ()
              (interactive)
              (call-interactively cmd)
              (call-interactively old))))))

    (define-before global-map (kbd "C-n")
      (lambda ()
        (interactive)
        (message "Going to the next line!")))

However, I think using "before advice" is a nicer solution for this,
because it integrates well with `describe-function'.

    (defun my-next-line-advice (&rest args)
      (message "Going to the next line!"))

    (advice-add 'next-line :before #'my-next-line-advice)

The arguments your advice function receives will be the same as those
for the original function you're advicing, if any. Check the
documentation for `add-function' for a description of all the different
kinds of advice and what arguments the advicing function receives.

-- 
john



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Rebind key and save/reuse previous bound function
  2015-10-31 20:22 ` John Mastro
@ 2015-11-01 22:08   ` Joe Riel
  2015-11-02  0:22     ` Emanuel Berg
  0 siblings, 1 reply; 8+ messages in thread
From: Joe Riel @ 2015-11-01 22:08 UTC (permalink / raw)
  To: John Mastro; +Cc: Help GNU Emacs

On Sat, 31 Oct 2015 13:22:29 -0700
John Mastro <john.b.mastro@gmail.com> wrote:

> Joe Riel <joer@san.rr.com> wrote:
> >
> > Is there a clean way save the function bound to a key
> > so that a new function can be created that is bound
> > to the same key, does something, then executes the
> > original bound function?
> 
> I don't think there's anything built-in that does exactly what you
> describe, but there are a few alternatives for doing it and all are
> pretty simple.
> 
> Something like this would probably be the most direct translation of
> your description:
> 
>     (defun define-before (map key cmd)
>       (let ((old (lookup-key map key)))
>         (define-key map key
>           (if (null old)
>               cmd
>             (lambda ()
>               (interactive)
>               (call-interactively cmd)
>               (call-interactively old))))))
> 
>     (define-before global-map (kbd "C-n")
>       (lambda ()
>         (interactive)
>         (message "Going to the next line!")))
> 
> However, I think using "before advice" is a nicer solution for this,
> because it integrates well with `describe-function'.
> 
>     (defun my-next-line-advice (&rest args)
>       (message "Going to the next line!"))
> 
>     (advice-add 'next-line :before #'my-next-line-advice)
> 
> The arguments your advice function receives will be the same as those
> for the original function you're advicing, if any. Check the
> documentation for `add-function' for a description of all the different
> kinds of advice and what arguments the advicing function receives.

Thanks.  Another user also suggested using advice.
I followed that advice 8-).



-- 
Joe Riel




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Rebind key and save/reuse previous bound function
  2015-11-01 22:08   ` Joe Riel
@ 2015-11-02  0:22     ` Emanuel Berg
  0 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2015-11-02  0:22 UTC (permalink / raw)
  To: help-gnu-emacs

Joe Riel <joer@san.rr.com> writes:

> Thanks. Another user also suggested using advice.
> I followed that advice 8-).

I'd say, if your ads are that poor, it is a vice
using them.

*rumbling laughter*

:)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-11-02  0:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-30  4:45 Rebind key and save/reuse previous bound function Joe Riel
2015-10-30  4:57 ` Joe Riel
2015-10-31 16:33   ` Emanuel Berg
2015-10-30  4:58 ` Joe Riel
2015-10-30 18:31 ` Doug Lewan
2015-10-31 20:22 ` John Mastro
2015-11-01 22:08   ` Joe Riel
2015-11-02  0:22     ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.