Monday, April 23, 2018

Re: Case-insensitive completefunc

On Monday 23 April 2018 13:53,
Tony Mechelynck <antoine.mechelynck@gmail.com> put forth the proposition:
>On Mon, Apr 23, 2018 at 1:34 PM, Tony Mechelynck
><antoine.mechelynck@gmail.com> wrote:
>> On Mon, Apr 23, 2018 at 1:18 PM, David Woodfall <dave@dawoodfall.net> wrote:
>>> Hi
>>>
>>> I've been reading the help to try to make the complete menu case
>>> insensitive and I see the 'icase' setting, but for the life of me I
>>> can't figure out how to use it.
>>>
>>> If I add it to the return value in my completefunc I just get errors.
>>>
>>> fun! UserComplete(findstart, base)
>>> let line = getline(line('.'))
>>> if line =~ '^\(To\|Cc\|Bcc\|From\|Reply-To\):'
>>> return CompleteEmails(a:findstart, a:base)
>>> endif
>>> endfun
>>>
>>> I've tried making the return value a list by encasing in {} and
>>> adding , 'icase': 1 (also '1').
>>>
>>> I've tried adding it to the end of the call to add an item to the
>>> list:
>>>
>>> for m in split(system('completeemails ' . shellescape(a:base)), '\n')
>>> call add(res, m)
>>> endfor
>>> add (res, 'icase': 1)
>>> return res
>>>
>>> etc.
>>>
>>> Any help is hugely appreciated.
>>
>> • What is CompleteEmails() ?
>> • Remember that a completefunc must return a Number when a:findstart
>> is 1, a List or a Dictionary when a:findstart is 0.
>> • Your system command executes a program named "completeemails" with
>> no command-line parameters and a one-line stdin. Is that what you
>
>Oops, my bad. It was a dot not a comma. With parameters and no stdin.
>Anyway on my openSUSE Linux system there is no "completeemails" in the
>$PATH. There is something named "complete" though. YMMV, though. Which
>OS are you on?
>
>> want? Then the output of that program is split at linefeed characters
>> — you might just as well use systemlist()
>>
>> Best regards,
>> Tony.

Hi

I detailed the function and script in my thread 'Problem with
completefunc and lists':

fun! CompleteEmails(findstart, base)
if a:findstart
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start - 1] =~ '[^:,]'
let start -= 1
endwhile
return start
else
let res = []
for m in split(system('completeemails ' . shellescape(a:base)), '\n')
call add(res, m)
endfor
return res
endif
endfun

fun! UserComplete(findstart, base)
let line = getline(line('.'))
if line =~ '^\(To\|Cc\|Bcc\|From\|Reply-To\):'
return CompleteEmails(a:findstart, a:base)
endif
endfun

And my completer script:

#################################
#!/bin/sh

afile="$HOME/.mutt/aliases"
base=$(echo "$@" | sed "s%^ %%g")

aliases=$(cut -d' ' -f2- $afile | grep -iE "^$base" | cut -d' ' -f2- \
| sed "s%^% %")
names=$(cut -d' ' -f3- $afile | grep -iE "^$base" \
| sed "s%^% %")
addresses=$(cut -d'<' -f2 $afile | cut -d'>' -f1 | grep -iE "^$base" \
| sed "s%^% %")

printf "%s\n%s\n%s" "$aliases" "$names" "$addresses" | sort -u
###############################

The script and function work fine.

When the menu is first activated it is case-insensitive because it uses 'grep
-i'. However, if I type more or backspace it becomes case-sensitive, which I
guess is the default for the completion menu. That's what I want to change.

Thanks

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: