Another completion bugfix

This commit is contained in:
Shy 2017-04-11 21:05:16 +02:00
parent 5ca5eb1532
commit 82b5876ed3

View file

@ -5,7 +5,8 @@
" Maintainer: Shy " Maintainer: Shy
" License: This file is placed in the public domain. " License: This file is placed in the public domain.
" "
" Usage: C4ctrl [get | open PRESET | set [w] [p] [f] [-magic] | text | write] " Usage: C4ctrl [get | open PRESET | set [w] [p] [f] [-magic] | text |
" write PRESET]
if exists("g:loaded_c4ctrl") if exists("g:loaded_c4ctrl")
finish finish
@ -131,11 +132,12 @@ function C4ctrl(prev_cursor_pos, mods, first_line, last_line, command, ...) rang
for i in range(a:0) for i in range(a:0)
let arg = a:000[i] let arg = a:000[i]
if strchars(arg) == 1 for room in ["wohnzimmer", "plenarsaal", "fnordcenter"]
if stridx("wpf", arg) != -1 if stridx(room, arg) == 0
let command_line = printf("%s -%s -", command_line, arg) let command_line = printf("%s -%s -", command_line, arg[0])
endif endif
elseif stridx("-magic", arg) == 0 endfor
if stridx("-magic", arg) == 0
let command_line = printf("%s --magic", command_line) let command_line = printf("%s --magic", command_line)
endif endif
endfor endfor
@ -204,8 +206,8 @@ function s:C4ctrlCompletion(ArgLead, CmdLine, CursorPos)
" The name of the command we are adding to Vim " The name of the command we are adding to Vim
let command_name = "C4ctrl" let command_name = "C4ctrl"
" A list of current cmd line arguments " A list of current cmd line arguments, starting from the first letter
let command_line = split(a:CmdLine) let command_line = split(strpart(a:CmdLine, match(a:CmdLine, "[A-Z]")))
" Check out if our name was abbreviated and modify accordingly " Check out if our name was abbreviated and modify accordingly
while index(command_line, command_name) == -1 while index(command_line, command_name) == -1
let command_name = strpart(command_name, 0, len(command_name) - 1) let command_name = strpart(command_name, 0, len(command_name) - 1)
@ -222,9 +224,9 @@ function s:C4ctrlCompletion(ArgLead, CmdLine, CursorPos)
" *************************** " " *************************** "
" Complete the 'open' command " " Complete the 'open' command "
" *************************** " " *************************** "
" ^ Note: the seconds part of the if rule (the part after '||') will " ^ Note: the seconds part of the if rule above (the part after '||')
" eval to true if a filename matches our command name better than the " will eval to true if a filename matches our command name better than
" actually given command name (eg. ':C4 open C4c') " the actually given command name (eg. ':C4 open C4c')
if a:ArgLead != "" if a:ArgLead != ""
if len(command_line) == command_index + 2 if len(command_line) == command_index + 2
return "open" return "open"
@ -255,7 +257,7 @@ function s:C4ctrlCompletion(ArgLead, CmdLine, CursorPos)
if a:ArgLead != "" if a:ArgLead != ""
return "set\n-magic" return "set\n-magic"
endif endif
return "w\np\nf\n-magic" return "wohnzimmer\nplenarsaal\nfnordcenter\n-magic"
elseif stridx("text", get(command_line, command_index + 1)) == 0 elseif stridx("text", get(command_line, command_index + 1)) == 0
" *************************** " " *************************** "
@ -270,9 +272,9 @@ function s:C4ctrlCompletion(ArgLead, CmdLine, CursorPos)
" **************************** " " **************************** "
" Complete the 'write' command " " Complete the 'write' command "
" **************************** " " **************************** "
" ^ Note: the seconds part of the if rule (the part after '||') will " ^ Note: the seconds part of the if rule above (the part after '||')
" eval to true if a filename matches our command name better than the " will eval to true if a filename matches our command name better than
" actually given command name (eg. ':C4 open C4c') " the actually given command name (eg. ':C4 open C4c')
if a:ArgLead != "" if a:ArgLead != ""
if len(command_line) == command_index + 2 if len(command_line) == command_index + 2
return "write" return "write"