Create command for auto-generating hook for current file
ahw opened this issue · comments
Initial work pushed to development in 6363b5134ee92613cf13abf2f23c9379e035ce01. It has since been merged to master but remains an undocumented "hidden feature." Here's the commit message:
CreateNewVimHook command
First argument is an event type. This is tab-completed. Second (optional)
argument is a regex pattern. The plugin will build the actual matching
pattern as follows:
let matchingPattern = '\v^' . YOUR_PATTERN . '$'
However, there still isn't a generalizable way of naming VimHook scripts
that are intended support arbitrary regex patterns outisde of the global-,
extension-, and filename-specific use cases. Currently, the CreateNewVimHook
command just names the hook file as it would any other filename-specific
hook file:
FILENAME.vimhook.sh
Two problems with this:
1. The extension need not necessarily be ".sh"
2. Although this VimHook will trigger according to the arbitrary regex pattern
passed to the CreateNewVimHook command, when the current Vim session is
closed that information is lost. When a new Vim session is opened, the
plugin will of course just assume that this is a filename-specific
VimHook as its naming pattern indicates.
Would be nice if there were a variant on this command to add the vimhook.bufferoutput
option key since I use that one a lot while building small programs from scratch.
The more I consider this the more I'm leaning towards just creating a handful of convenience commands to cover the most common cases. Something like
- CreateBabelHook
- CreatePythonHook
- CreateNodeHook
- CreateRubyHook
- etc.
It would be a lot more convenient for the user than having to remember the arguments to some generic hook-creating function. Of course they'd all just be thin wrappers for the generic version which a power user could invoke if they wanted. Something like
:CreateVimHook BufWritePost /usr/bin/python bufferoutput
Could provide a second optional arg to provide the filename of the hook. If left off, the hook name will be what I'm using already: the-current-filename.eventname.vimhook.sh