So at work, I’ve got to work from two different repositories. The files map to essentially the same place, but one path has ‘data’ in it.
It’s relatively trivial to write a defun that determines if the file is in the data directory or not, and so which repository I actually want to check out from. But I can’t figure out a way to call my function before any p4 commands without explicitly rebinding the keys to do it, and even that is sort of a big hack. I’d really just like it to run every time I try to check out or revert a file and set the p4port as I want it to.
All the hooks in the p4 system seem to be called when I don’t want them to be. I tried calling my defun on the p4-mode-hook, but that hook only runs when the mode is set, and files that aren’t in the repository are rejected before I ever get my defun to do anything. :/
There are a couple of approaches that you could use. First, you could consider adding the desired functions to
pre-command-hook, with a predicate to check whether the current buffer is operating inp4-mode, i.e.:This will indiscriminately execute the functions that you include in the body of the above
lambdabefore any command in ap4-modebuffer. If that’s overkill and you need to be more selective about when to execute said functions, you should probably individually advise each of thep4commands that should first execute your functions before running, e.g.:See the Advising functions section of the Emacs manual for additional details.