Author Topic: Add a way to hook immediately before/after any command  (Read 1717 times)

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Add a way to hook immediately before/after any command
« on: December 30, 2011, 09:19:57 AM »
As of v16 there's no way to hook immediately before any command or immediately after any command.  I'd like to see a couple new callbacks for that.

- before_command, called immediately before a command is invoked.
- after_command, called immediately after a command is invoked.

In this context "command" would correspond to something bound to a key.  But when a recorded macro is bound to a key then it's trickier:  in recorded macros it should correspond more closely to the original key presses that were recorded, instead of the key press that invokes the recorded macro.

These would enable new scenarios, for example:
- Hook after_command and set a timer to refresh something after X amount of time elapses after the most recent command.
- Hook both before_command and after_command and detect when the cursor moves to a different line, and do some deferred auto-formatting.

I have a few macros from another editor that I wish I could port to SE, but can't do so without some kind of before_command/after_command callbacks.

Yes, hooking these callbacks can be costly in terms of CPU processing.  It was a caveat in the documentation in the other editor I used, but in practice was never an issue because macro writers understood the callbacks had to be lightweight.