Skip to content

Question: Accept a list item programmatically #524

phalkunz opened this Issue Feb 3, 2014 · 4 comments

3 participants

phalkunz commented Feb 3, 2014

I'm writing a plugin that lists related files to the file in the current buffer. It's mainly for working with MVC frameworks where view, model, and template files use the same filename (with different file extensions). I really like the list prompt in ctrlp.

However, there's one problem. If there's only one related file found, I'd like it to accept the file right away but couldn't get it to work. I've tried ctrlp#acceptfile() and sending key combo <CR> but none worked. I would much appreciate it if anyone can give me some advice on this.

Cheers :)

kien commented Feb 5, 2014

How exactly did you do those? Checking if there's only one file then call the accept function right from the init function should do it. If you want to send <cr>, try using feedkey().

kien commented Feb 5, 2014

Actually, I don't think this is possible, at least not yet. The init function is called before the prompt is rendered to properly close it. And there's no other point to accept the file until a selection is made by the user.

phalkunz commented Feb 5, 2014

Both ctrlp#accept and feedkeys didn't work. Wish there were hooks before and after the prompt is rendered with the list built in initx passed in. Might be there's no other uses beside my case.

Anyways, I really appreciate your help :)

@phalkunz phalkunz closed this Feb 5, 2014
bkudria commented Aug 14, 2014

+1 for this functionality!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.