Skip to content

Loading…

allow for argument prefixing #1

Closed
wants to merge 1 commit into from

2 participants

@mattsacks

this plugin is excellent - I'm definitely going to use it with a lot of my common commands. one use I'm already getting great mileage out of is supplanting my vim-fuzzee plugin without having to manually tab to the result of the globbed files.

something I thought could be pretty cool is to create mappings that prefix a command to reduce typing common arguments. I've modified the source so that it will allow for this, but I haven't done too much extensive testing into what I've possibly broken.

as an example: nnoremap <Leader>js :call SkyBison("F app/jav*", 0)

This will call the F command with app/jav*<user input> and allow for completion from the results of the command without having to manually hit to see them.

@mattsacks mattsacks allow for argument prefixing
example: nnoremap <Leader>js :call SkyBison("F app/jav*", 0)
This will call the F command with app/jav*<user input> and allow for
completion from the results of the command.
ff3fc3c
@paradigm
Owner

I should note you can do something comparable without your pull:

nnoremap js :call SkyBison("F",0)app/java*

The mapping keeps feeding keys into the function's getchar()'s after the is called.

We seem to have very different coding styles (you use spaces for indentation where I use tabs, you drop the variable scope prefix when unnecessary where as I tend to be explicit about it every time). Since I'm going to refactor everything to be more readable anyways, rather than pulling in your code, unifying the style, and then refactoring, I might turn down your pull and re-implement your idea myself when I'm refactoring. Not that there's anything wrong with your code, it just seems like a path of lesser resistance to the same end result.

Currently, SkyBison internally differentiates between the command and the argument (as I'm sure you've noticed). With that in mind, there are three major ways to go about implementing your idea:
(1) Attach the prefix to the command, as you did. This means the user cannot delete parts of the prefix without exiting the plugin (which may or may not be desirable).
(2) Attach the prefix to the argument. This would be simpler to implement than the first option, as it is just setting the default argument from an empty string to the prefix. However, this means the user can delete parts or all of the prefix (which may or may not be desirable).
(3) Stop internally differentiating between the command and the argument. This has a number of repercussions. The user can delete not only the prefix but also the command. If this can be made to work well, this could make SkyBison("",0) act as a mostly functional replacement for not just a individual cmdline commands but the cmdline itself. Perhaps a cnoremap could be made to convert an in-progress cmdline entry to SkyBison. The major barrier here is that, at first glance, there is no really good way to have a sufficiently flexible auto-. I could assume when Vim's cmdline-completion no longer returns more than one possible option we've exhausted the number of cmdline-completion'able arguments. However, commands such as :wqall would then wait for an argument, as that can take an argument, even if people usually don't give it one.

Any preferences? I'm probably going to leave it to churn in the back of my mind for a while, as all three have appealing aspects.

@mattsacks

I'm totally cool with you declining the pull and I apologize for introducing a different coding style into your file.

This pull serves my needs and might not be applicable to most users. Unfortunately, nnoremap <Leader>js :call SkyBison("F",0)app/java*<CR> doesn't quite do what I want.

What I want is a mapping that prefixes what I type after <Leader>js to be :F app/java* and then show all completions based on that. As I type along, app/java* is consistently prefixed in front of my input.

All 3 options you've introduced don't seem too bad. Coincidentally, my attempt at thinking about an auto-completion system for the command line had to do with adding a new option to wildmode, but I like your plugin much better :smile:

If I had to pick one though, I probably wouldn't. You could add an optional, additional third argument (I know, blech), that determines whether any of the passed in cmd argument can be modified once SkyBison has been called, and default it to false.

As to the flickering - it's only present for me in Terminal Vim (which, thankfully, I don't use often) and isn't in MacVim (at least for me). The cause of which are your calls to redraw. Unfortunately, I don't know of an alternative to the system you've set up in SkyBison.

Hope that helps!

@paradigm
Owner

I apologize for introducing a different coding style into your file.

No need to apologize, that's just how life without a universal coding style standard is.

To make sure I understand the situation:
The problem with my nnoremap proposal is that the prefix part can be changed, yes? If the user could not <bs> over it, it'd be good, yes? I'm leaning towards breaking the internal differentiation between command and argument. If I do that, but leave some way to keep the user from changing the content passed in the first argument to SkyBision(), it'd serve what you're looking for, yes?

If so, I'll likely do that. Shouldn't be hard to implement.

@paradigm
Owner

This issue is over a year old without any response to my questions about exactly what is being asked; I'm closing it. If you ever find your way back here do not hesitate to re-open it and explain in more detail and I'll see what I can do.

@paradigm paradigm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 3, 2012
  1. @mattsacks

    allow for argument prefixing

    mattsacks committed
    example: nnoremap <Leader>js :call SkyBison("F app/jav*", 0)
    This will call the F command with app/jav*<user input> and allow for
    completion from the results of the command.
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 12 deletions.
  1. +42 −12 plugin/skybison.vim
View
54 plugin/skybison.vim
@@ -22,11 +22,18 @@ function! SkyBison(cmd,autoenter)
" build arg up from user input
let l:arg = ""
redraw
+ " if the cmd has an argument appended to it
+ if a:cmd =~ '\s\S\+$'
+ let prefix = matchstr(a:cmd, '^\zs.\+\ze\s') . ' '
+ let cmd = a:cmd
+ else
+ let cmd = a:cmd . ' '
+ endif
while 1
" Determine cmdline-completion options. Huge thanks to ZyX-I for
" helping me do this so cleanly.
let d={}
- execute "silent normal! :".a:cmd." ".l:arg."\<c-a>\<c-\>eextend(d, {'cmdline':getcmdline()}).cmdline\n"
+ execute "silent normal! :".cmd.l:arg."\<c-a>\<c-\>eextend(d, {'cmdline':getcmdline()}).cmdline\n"
if has_key(d, 'cmdline')
let l:results = split(strpart(d['cmdline'],stridx(d['cmdline'],' ')+1),'\\\@<! ')
else
@@ -43,8 +50,12 @@ function! SkyBison(cmd,autoenter)
elseif len(results) == 1
if a:autoenter
redraw
- echo ":".a:cmd." ".l:results[0]
- execute "silent ".a:cmd." ".l:results[0]
+ echo ":".cmd.l:results[0]
+ if exists('prefix')
+ execute "silent ".prefix.l:results[0]
+ else
+ execute "silent ".cmd.l:results[0]
+ endif
let &more = l:initmore
return 0
else
@@ -53,9 +64,9 @@ function! SkyBison(cmd,autoenter)
endif
" get input from user
if l:ctrlv == 1
- echo ":".a:cmd." ".l:arg."^"
+ echo ":".cmd.l:arg."^"
else
- echo ":".a:cmd." ".l:arg
+ echo ":".cmd.l:arg
endif
let l:input = getchar()
if type(l:input) == 0
@@ -84,25 +95,44 @@ function! SkyBison(cmd,autoenter)
let l:arg = l:arg[:-2]
endwhile
elseif l:input == "\<tab>" || l:input == "\<c-l>"
- execute "silent normal! :".a:cmd." ".l:arg."\<c-l>\<c-\>eextend(d, {'cmdline':getcmdline()}).cmdline\n"
+ if exists('prefix')
+ let cmd = prefix
+ endif
+ execute "silent normal! :".cmd.l:arg."\<c-l>\<c-\>eextend(d, {'cmdline':getcmdline()}).cmdline\n"
if has_key(d, 'cmdline')
let l:arg = strpart(d['cmdline'],stridx(d['cmdline'],' ')+1)
endif
elseif l:input == "\<cr>"
if len(l:results) == 1
- echo ":".a:cmd." ".l:results[0]
- execute "silent ".a:cmd." ".l:results[0]
+ echo ":".cmd.l:results[0]
+ if exists('prefix')
+ execute "silent ".prefix.l:results[0]
+ else
+ execute "silent ".cmd.l:results[0]
+ endif
else
- echo ":".a:cmd." ".l:arg
- execute "silent ".a:cmd." ".l:arg
+ echo ":".cmd.l:arg
+ if exists('prefix')
+ execute "silent ".prefix.l:results[0]
+ else
+ execute "silent ".cmd.l:results[0]
+ endif
endif
let &more = l:initmore
return 0
elseif l:input =~ "[1-9]" && len(results) >= l:input
let l:arg = l:results[l:input-1]
+ if exists('prefix')
+ let cmd = prefix
+ endif
if a:autoenter
- echo ":".a:cmd." ".l:results[l:input-1]
- execute "silent ".a:cmd." ".l:arg
+ if exists('prefix')
+ echo ":".prefix.l:results[l:input-1]
+ execute "silent ".prefix.l:arg
+ else
+ echo ":".cmd.l:results[l:input-1]
+ execute "silent ".cmd.l:results[0]
+ endif
let &more = l:initmore
return 0
endif
Something went wrong with that request. Please try again.