Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildmenu source #443

Closed
majkinetor opened this issue Jan 3, 2014 · 24 comments
Closed

Wildmenu source #443

majkinetor opened this issue Jan 3, 2014 · 24 comments

Comments

@majkinetor
Copy link

I don't like that you have to iterate over wildmenu items when there are lots of them.

For instance, typing unite gives me huge number of wildmenu items. Is it possible to create a source of completition items ?

I looked in the vim documentation and around how could such list be obtained but didn't have any luck.

The source would need to have an argument that would be always supplied by the user or it could be also specified as command line mapping ( TAB would be logical choice) that will get the currently typed sentence and feed it to source as an argument. From that point on you could use fuzzy search to reduce candidates.

@Shougo
Copy link
Owner

Shougo commented Jan 3, 2014

It cannot be implemented. Because, Vim's command line has few features for custom.
For example, we cannot get complete items from command line completion.
If you want to implement it, you should request it or create patch for it.

@Shougo Shougo closed this as completed Jan 3, 2014
@majkinetor
Copy link
Author

For example, we cannot get complete items from command line completion.

I managed to create the function that returns competition info. It uses ctrl-a (see h c_CTRL-A) to obtain the info and the fact that it will be inserted in command line history asap where I yank the last line and close it with <c-f> yy o <cr>

fu! Get(cmd)
    exe "nn <buffer> z& :" . a:cmd . "<c-a><c-f>yyo<cr>"
    norm z&
    return split(@0)
endf

It looks like this list could be used as a source. It can even be used with help:

echo Get('help a')

The function obviously needs some love (i.e. save 0 register and use safer map but it proves the point).

Output : echo Get('Neo')

['NeoBundle', 'NeoBundleCheck', 'NeoBundleClean', 'NeoBundleDepends', 'NeoBundleDirectEdit', 'NeoBundleDirectInstall', 'NeoBundleDisable', 'NeoBundleDocs', 'NeoBundleFetch', 'NeoBundleInstall', 'NeoBundleLazy', 'NeoBundleList', 'NeoBundleLocal', 'NeoBundleLog', 'NeoBundleRecipe', 'NeoBundleReinstall', 'NeoBundleSource', 'NeoBundleUpdate', 'NeoBundleUpdatesLog', 'NeoComplCacheAutoCompletionLength', 'NeoComplCacheCachingBuffer', 'NeoComplCacheCachingDictionary', 'NeoComplCacheCachingInclude', 'NeoComplCacheCachingSyntax', 'NeoComplCacheCachingTags', 'NeoComplCacheCachingVim', 'NeoComplCacheClean', 'NeoComplCacheDisable', 'NeoComplCacheDisableCaching', 'NeoComplCacheEnable', 'NeoComplCacheEnableCaching', 'NeoComplCacheLock', 'NeoComplCacheLockSource', 'NeoComplCacheOutputKeyword', 'NeoComplCachePrintSource', 'NeoComplCacheSetFileType', 'NeoComplCacheToggle', 'NeoComplCacheUnlock', 'NeoComplCacheUnlockSource', 'NeoSnippetClearMarkers', 'NeoSnippetEdit', 'NeoSnippetMakeCache', 'NeoSnippetSource']

@majkinetor
Copy link
Author

BTW, in order to prevent constant function call (as it could make screen flicker) its enough to call it only once with first letter only (set list=Get("N")) then filter the list as the keys are input. So the function needs to be called only on zero letters (and output could be cached for the current vim session)

@Shougo Shougo reopened this Jan 8, 2014
@Shougo
Copy link
Owner

Shougo commented Jan 8, 2014

I think this feauture must be implemented by external sources. Not unite.vim internal source.
You should make new source for it.

@majkinetor
Copy link
Author

OK, here it is. Its still not polished yet but it should work: https://github.com/majkinetor/unite-cmdmatch

If I could only figure out how to prevent visual glitch while gathering candidates (i.e. how to hide cmd line) all wildmenu options would be supported - currently in completes only last word.

@majkinetor
Copy link
Author

BTW, plugin is not loaded until first time I type :Unite cmdmatch. That is why I have sil! call unite#sources#cmdmatch#define() to force it. How can I solve that ?

@Shougo
Copy link
Owner

Shougo commented Jan 10, 2014

Yes. It is feature. You should use plugin directory for initialize.
For example, mru sources.

@Shougo
Copy link
Owner

Shougo commented Jan 13, 2014

I checked your code.

https://github.com/majkinetor/unite-cmdmatch

  1. You should provide plugin mappings like <Plug>(unite_cmdmatch_complete). User can map it.
  2. You should not call unite#sources#cmdmatch#define() in plugin/unite-cmdmatch.vim. You should define plugin keymapping only.
cnoremap <Plug>(unite_cmdmatch_complete) <c-f>^"vyg_ddo<cr>:Unite -buffer-name=cmdmatch -direction=botr -start-insert -input=<c-r>=strpart(@v, strridx(@v, ' ')+1)<cr> cmdmatch:<c-r>=escape(@v,' ')<cr><cr>

@majkinetor
Copy link
Author

Fixed: c4b818

Thanks.

@Shougo
Copy link
Owner

Shougo commented Jan 13, 2014

if !hasmapto('<Plug>(unite_cmdmatch_complete)')
    cm <c-o> <Plug>(unite_cmdmatch_complete)
en
cno <Plug>(unite_cmdmatch_complete) <c-f>^"vyg_ddo<cr>:Unite -buffer-name=cmdmatch -direction=botr -start-insert -input=<c-r>=strpart(@v, strridx(@v, ' ')+1)<cr> cmdmatch:<c-r>=escape(@v,' ')<cr><cr>

It should be defined in plugin/unite-cmdmatch.vim.

@majkinetor
Copy link
Author

Did it.

@Shougo
Copy link
Owner

Shougo commented Jan 14, 2014

Thanks. I will try it.

@Shougo
Copy link
Owner

Shougo commented Jan 14, 2014

I tested your plugin, but it didn't work...

cmdmatch

@majkinetor
Copy link
Author

Thats strange. It works on 4 different OS-es here.

<c-f>^"vyg_ddo<cr> means

  • <c-f> open command line history window (from there we are in normal mode)
  • ^ - go to start of the line
  • "vyg_ - copy line to the end without new line char
  • dd - delete line
  • o<cr> - open new line and press enter(this one is used to close window because enter in insert mode does that)

The point of that part is to grab the text user typed before invoking the hotkey.

You can replicate this manually after typing something in command line and see what part is problematic. At the end you should have typed text in v register, i.e.

:something <c-f>^"vyg_ddo<cr>

and later echo @v should give something

@majkinetor
Copy link
Author

Also, you can test it by invoking command manually:

:Unite cmdmatch:neo -input=neo

@Shougo
Copy link
Owner

Shougo commented Jan 14, 2014

Oh, errors is happened..

error

This is my settings.

NeoBundleLazy 'majkinetor/unite-cmdmatch' , {
      \ 'depends':  'Shougo/unite.vim',
      \ 'mappings' : [['c', '<Plug>(unite_cmdmatch_complete)']] }

@majkinetor
Copy link
Author

Ah, thats how you lazy load it.. I tried bunch of things and finally reverted to non-lazy. Perhaps you want to update the documentation where it says: Note: You can omit "autoload" dictionary. It is useful for |:NeoBundleLazy| command and specify that you can put its keys directly in options.

This works here:

NeoBundleLazy 'majkinetor/unite-cmdmatch', { 'depends': 'Shougo/unite.vim', 'mappings' : [['c', '(unite_cmdmatch_complete)']] } "
cm <c-o> <Plug>(unite_cmdmatch_complete)

Looking at error info I can't say why error occurred.

undefined variable NeobundleCheck ?

What happens when you execute this function:

fu! g:GetCmdCompletition(cmd)
    let [cwh,ls,v] = [&cwh, &ls, @v]
    set cwh=1 ls=0
    exe 'nn <buffer> z&u :' . a:cmd . '<c-a><c-f>"vyyo<cr>'
    norm z&u
    let res = split(@v)
    let [&cwh,&ls,@v] = [cwh,ls,v]
    return res
endf
:echo g:GetCmdCompletition('neo')

@Shougo
Copy link
Owner

Shougo commented Jan 14, 2014

I think your function executes command line like :NeoBundle... Oh...
I tested it in default settings. OK. I will search the problem.

@majkinetor
Copy link
Author

So I presume that you didn't get the list with :echo g:GetCmdCompletition('neo') ?

Line

exe 'nn <buffer> z&u :' . a:cmd . '<c-a><c-f>"vyyo<cr>'

first prints the argument on cmd line in order to complete it, then calls <c-a> (insert every completed item on command line), then repeats the same thing from before (opens cmd history and yanks last line)

OK, I will checkout your .vimrc and see if I can find whats wrong ...
You should manually check above key sequence to see if you get the in @v that list... or if <c-a> is actually working

@Shougo
Copy link
Owner

Shougo commented Jan 14, 2014

Hmmm... You source print errors in my .vimrc.
I think your source is too tricky. It can break easily.
I think to add command line completion interface is better(Yes, it is not easy).

@majkinetor
Copy link
Author

Without telling me what exactly did you do I can't deduce whats wrong. This is really simply simple function. You should be able to reproduce it manually without any problems to obtain the completion list.

So tell me. What does this mapping return:

nn zz :Neo<c-a><c-f>"vyyo<cr>:echo @v<cr>

My output is

NeoBundle NeoBundleCheck NeoBundleClean NeoBundleDirectInstall NeoBundleDisable NeoBundleDocs NeoBundleExtraEdit NeoBundleFetch NeoBundleInstall NeoBundleLazy NeoBundleList NeoBundleLocal NeoBundleLog NeoBundleRecipe NeoBundleReinstall NeoBundleSource NeoBundleUpdate NeoBundleUpdatesLog NeoComplCacheAutoCompletionLength NeoComplCacheCachingBuffer NeoComplCacheCachingDictionary NeoComplCacheCachingInclude NeoComplCacheCachingSyntax NeoComplCacheCachingTags NeoComplCacheCachingVim NeoComplCacheClean NeoComplCacheDisable NeoComplCacheDisableCaching NeoComplCacheEnable NeoComplCacheEnableCaching NeoComplCacheLock NeoComplCacheLockSource NeoComplCacheOutputKeyword NeoComplCachePrintSource NeoComplCacheSetFileType NeoComplCacheToggle NeoComplCacheUnlock NeoComplCacheUnlockSource NeoSnippetClearMarkers NeoSnippetEdit NeoSnippetMakeCache NeoSnippetSource

@Shougo
Copy link
Owner

Shougo commented Jan 14, 2014

It is in my configuration.

simple

@majkinetor
Copy link
Author

I see. There is a new, awesome method to get completion data which is much more robust, faster and without visual glitch. It would also allow to complete exactly the same as in wildmenu. I will update plugin soon and let you know.

@Shougo
Copy link
Owner

Shougo commented Jan 14, 2014

Thanks! I wait until you implement it.

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

No branches or pull requests

2 participants