Is there a way to hook onto command A, so that B is always called after A executes?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think the most straight-forward way to accomplish this is through the use of advice.
You would do something along the lines of:
This approach has the advantage that it works even when command-A is redefined. It does not, however, work on macros or on primitive functions called from the C code. But, in practice the thought of advising those functions is rare.
That said, it might be worth looking into just defining a new command (
command-C) which first callscommand-Aand thencommand-B.You could also play around with symbol function indirection and writing a new command.
It kind of depends on what you’re trying to solve.