All,
Is there a way to detect whether Vim has input characters
waiting in the typeahead buffer? Internal to Vim, there are a
couple of functions that seem promising (ui_char_avail(),
input_available()), but I don't see how to access them from
Vimscript (or Python).
I'm looking to do something like the following:
if !input_available()
call feedkeys("keys")
endif
My overall goal is to make a dynamically computed snippet body
for use with the UltiSnips plugin. A generic trigger word would
expand to a snippet body that calculates a more specific trigger
word based on conditions. As an example, consider having a set
of "template" snippets based on filetype:
Trigger Body
template_python #!/usr/bin/env python ...
template_shell #!/bin/bash ...
template (delegate to template_&filetype)
The user would type the generic trigger "template", then logic
in that snippet's body would calculate a new trigger word (e.g.,
"template_python") and expand that snippet. It's easy enough to
have the "template" snippet body calculate a new trigger (e.g.,
"template_python") and replace it for the user. It's harder to
cause that computed template trigger to expand. I can place a
call to feedkeys() in the template body, but because UltiSnips
evaluates the template body multiple times during snippet
expansion, the call to feedkeys() is invoked repeatedly (three
times, it appears). Checking for input in the typeahead buffer
would allow the call to feedkeys() to occur just once regardless
of how many times the snippet body were to be expanded.
There might also be a clever way to solve this using UltiSnips
as-is, or to extend UltiSnips in some way to eliminate the need
to check the typeahead buffer. I'm currently using a
work-around that avoids defining "template" as a true snippet.
After a failed attempt to expand a snippet trigger, it performs
a hard-coded check for the word "template" on the current line;
if found, it calls feedkeys() to delegate to the real template.
While this works, I'd prefer a solution that doesn't involve
hooking the input keymaps for UltiSnips and hard-coding a check
for a pseudo-trigger.
Any ideas of suggestions are welcome.
Thanks,
Michael Henry
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tuesday, September 30, 2014
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment