Hi, Here's version 4 of a proposal for supporting hooks on commands. Changes to V3 are fairly minimal; we had an idea of having a global cmd_prepare() function which would set various struct types depending on a flag set by the command. This has helped reduce the need for similar prepare() functions in each of the commands. As a result, only a handful of commands now have their own prepare() function.
Because prepare() is now no-longer defined per-command, there is no easy way for commands to advertise that they don't support hooks. I've added in a CMD_PREPARE_NONE flag for this, which isn't currently used by any command---to me though such a flag to opt-out of hooks feels wrong; there should be a better way to do that. As a consequence, I think now any command has the potential to run hooks. We ought to investigate this. Nicholas, you had some concerns that because prepare() calls various cmd_find*() functions that they end up calling cmdq->error() and that to you feels wrong? As I think I mentioned on IRC, I don't consider this a problem. It would mean up-front that a before-* hook wouldn't run, due to something more serious than a run-time problem when the command runs. That way, a before-* hook wouldn't run at all if prepare() threw the validation out. I'm considering that a good thing. Note also that this doesn't change the fact that the command would still fail in exec(); it's just that it now fails slightly earlier. If you're still not happy with that, the only thing I can suggest is that we rip out the cmdq->error() stuff from cmd_find_*() and have an after-the-fact check to see if the result of calling cmd_find_*() was fatal; but that would mean updating every single caller to support this, so I am not sure it's worth it. I am unclear on how hook support as I'm proposing it should work with command-mode. For those of you playing a long at home, you can also get these patches here: https://github.com/ThomasAdam/tmux/tree/ta/hooks Any questions, do please ask. Kindly, -- Thomas Adam Thomas Adam (3): Define hooks infrasructure Convert commands to use prepare() Add man page entry for hooks Makefile.am | 3 ++ cmd-attach-session.c | 13 +++--- cmd-bind-key.c | 4 +- cmd-break-pane.c | 9 +++- cmd-capture-pane.c | 7 +++- cmd-choose-buffer.c | 9 ++-- cmd-choose-client.c | 9 ++-- cmd-choose-list.c | 9 ++-- cmd-choose-tree.c | 20 ++++++--- cmd-clear-history.c | 10 +++-- cmd-clock-mode.c | 10 +++-- cmd-command-prompt.c | 7 +++- cmd-confirm-before.c | 7 +++- cmd-copy-mode.c | 8 ++-- cmd-delete-buffer.c | 4 +- cmd-detach-client.c | 25 +++++++++--- cmd-display-message.c | 47 ++++++++++++++------- cmd-display-panes.c | 10 +++-- cmd-find-window.c | 9 ++-- cmd-has-session.c | 11 ++--- cmd-if-shell.c | 35 +++++++++++----- cmd-join-pane.c | 29 ++++++++++--- cmd-kill-pane.c | 9 ++-- cmd-kill-server.c | 4 +- cmd-kill-session.c | 7 +++- cmd-kill-window.c | 9 +++- cmd-link-window.c | 24 +++++++++-- cmd-list-buffers.c | 4 +- cmd-list-clients.c | 14 +++---- cmd-list-commands.c | 4 +- cmd-list-keys.c | 4 +- cmd-list-panes.c | 25 ++++++++++-- cmd-list-sessions.c | 4 +- cmd-list-windows.c | 19 +++++++-- cmd-load-buffer.c | 4 +- cmd-lock-server.c | 34 +++++++++++---- cmd-move-window.c | 29 +++++++++++-- cmd-new-session.c | 7 +++- cmd-new-window.c | 25 ++++++++++-- cmd-paste-buffer.c | 10 +++-- cmd-pipe-pane.c | 8 +++- cmd-queue.c | 56 +++++++++++++++++++++++++ cmd-refresh-client.c | 7 +++- cmd-rename-session.c | 7 +++- cmd-rename-window.c | 8 ++-- cmd-resize-pane.c | 8 +++- cmd-respawn-pane.c | 9 +++- cmd-respawn-window.c | 8 +++- cmd-rotate-window.c | 8 ++-- cmd-run-shell.c | 10 ++++- cmd-save-buffer.c | 8 +++- cmd-select-layout.c | 15 +++++-- cmd-select-pane.c | 30 +++++++++++--- cmd-select-window.c | 50 +++++++++++++++++++---- cmd-send-keys.c | 13 ++++-- cmd-server-info.c | 4 +- cmd-set-buffer.c | 4 +- cmd-set-environment.c | 7 +++- cmd-set-hook.c | 90 ++++++++++++++++++++++++++++++++++++++++ cmd-set-option.c | 8 +++- cmd-show-environment.c | 7 +++- cmd-show-hooks.c | 61 +++++++++++++++++++++++++++ cmd-show-messages.c | 10 +++-- cmd-show-options.c | 30 +++++++++++--- cmd-source-file.c | 4 +- cmd-split-window.c | 9 +++- cmd-start-server.c | 4 +- cmd-suspend-client.c | 10 +++-- cmd-swap-pane.c | 9 ++-- cmd-swap-window.c | 26 ++++++++---- cmd-switch-client.c | 21 +++++++--- cmd-unbind-key.c | 4 +- cmd-unlink-window.c | 9 ++-- cmd-wait-for.c | 4 +- cmd.c | 50 +++++++++++++++++++++++ hooks.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ session.c | 2 + tmux.1 | 79 +++++++++++++++++++++++++++++++++++ tmux.c | 2 + tmux.h | 90 +++++++++++++++++++++++++++++++--------- 80 files changed, 1183 insertions(+), 246 deletions(-) create mode 100644 cmd-set-hook.c create mode 100644 cmd-show-hooks.c create mode 100644 hooks.c -- 1.8.4.rc2 ------------------------------------------------------------------------------ Introducing Performance Central, a new site from SourceForge and AppDynamics. Performance Central is your source for news, insights, analysis and resources for efficient Application Performance Management. Visit us today! http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users