Closed lervag closed 9 months ago
@lervag Does PR #28 work as intended for you?
No, not quite. The main motivation from my side was to have $FILE_PATH
available such that I could do e.g. vim.fn.fnamemodify(...)
or similar on the result.
I looked at the code, and it seems like what I'm asking might require some larger refactoring. It seems you are evaluating the config function when initializing the plugin. My suggestion would only be relevant if the config value is evaluated as a function only when it is used (and every time it is used.
No, scratch that, I'm partly wrong. But: Instead of evaluating the template function in .get_option
, you should evaluate the function the .insert_markup
function only after the placeholders are ready to be interpolated, here:
That is, above these lines, you should check if template
is a function, and if it is, then you replace it with the result of the function where you pass a context object that contains the placeholder values.
I hope I'm being more clear on what I'm thinking now?
So, what I wanted was to have the values in placeholders interpolated already at this point, before you call val(placeholders). And in this case, I believe it is better to call the object "context" or similar instead of placeholders, to avoid confusing the placeholder names with the interpolated values. (From PR)
That makes sense to me. I understand now. This certainly has more value than simply returning the placeholder strings.
That is, above these lines, you should check if template is a function, and if it is, then you replace it with the result of the function where you pass a context object that contains the placeholder values.
That's probably the easiest solution with the current state of the code. I'll look into it.
Cool, thanks!
It would be nice if we could have a
template
option that allows a function argument. Some context should be available as function arguments. E.g.:The function return value should be a possibly parameterized template string. Thus, it can contain the placeholder values such as
$CURSOR
or similar. And the context argument should have the relevant context (more or less the placeholder variables, but perhaps there are some more relevant stuff).Personally, I would see myself using this in some specific cases where I want to put the captured images into a custom directory. But even though the text I'm writing is in a file located elsewhere, I still want the link to be fully relative to the media path. I can use the
$FILE_NAME
for this, but then I have to keep things flat.