added callback feature to browse output #7

Merged
merged 2 commits into from Apr 29, 2011

Conversation

Projects
None yet
2 participants
Contributor

SethMilliken commented Apr 29, 2011

Since there may be specific operations you want to perform on the selection returned from a tlib#input#List(), I implemented a new function
tlib#cmd#BrowseOutputWithCallback(callback, command) that executes the CALLBACK function passing the selection as an argument.

As a practical example of this new functionality, I also added a new TBrowseScriptnames command that allows you to select from the :scriptnames output and opens the selected file in the current window.

(I also reimplemented tlib#cmd#BrowseOutput(command) using a callback for DRYness.)

I wrote documentation for these, emulating other tlib documentation; but I wasn't able to determine how you generate the help docs from this markup (I sure would like to know! :-)

Please let me know if you would like me to make any further changes before accepting, or if you don't think this is an appropriate addition to tlib.

SethMilliken added some commits Apr 29, 2011

@SethMilliken SethMilliken added tlib#cmd#BrowseOutputWithCallback function and :TBrowseScriptna…
…mes command

- reimplemented tlib#cmd#BrowseOutput with tlib#cmd#BrowseOutputWithCallback
- added callback function for default tlib#cmd#BrowseOutput behavior
- added callback function for :scriptnames output (tlib#cmd#ParseScriptname)
- added :TBrowseScriptnames command specifically for opening files in :scriptnames
dd0dbe1
@SethMilliken SethMilliken tlib#cmd#BrowseOutputWithCallback function and :TBrowseScriptnames co…
…mmand documentation
be9f071

@tomtom tomtom merged commit be9f071 into tomtom:master Apr 29, 2011

Owner

tomtom commented Apr 29, 2011

Thanks. I was somehow surprised that TBrowseScriptnames wouldn't let me select multiple files. But since tlib#cmd#BrowseOutputWithCallback() is a general purpose function using single selection is safer.

The docs are generated with vimdedoc.rb (see https://github.com/tomtom/vimtlib/tree/master/ruby). I'm not happy with the script's code but it works for my own vim plugins.

Contributor

SethMilliken commented Apr 29, 2011

I wasn't familiar with multiple selection from a tlib#input#List(), so that's the main reason it's not there. I could add it, if you like. I think it should be pretty easy to check in the callback whether the incoming argument is a String or a List and act accordingly.

I'm not sure what the proper behavior would be in the case of multiple selections for an "edit file" callback. Add all of the files to the arglist? Edit all of them in turn, leaving the last one active? Create new splits for each? New tabs? Use some existing setting to determine proper behavior?

Owner

tomtom commented May 19, 2011

As long as nobody misses it, there probably is no use in improving the function.

Most of my tlib-related plugins usually edit the files right away. People who stay closer to vim's spirit would probably prefer adding the files to the arglist. An extra option could be of use for those plugins too. Could it be the command to use? E.g.

let g:tlib_edit_cmd = 'edit'

Users could also set it to: arga, split, vert split, tabe

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment